Try/Catch Again

Hi everybody,

there has been a very interesting discussion about when to use try/catch sequences in this forum:
[URL=“wmusers.com”]wmusers.com

wMUser ‘nath’ was talking about throwing exceptions back to the parent service. How is this done in Developer? Just leave out the try-catch-sequences? Where can I then (as in Java) deposit the e.g. “throws FileNotFoundException, IOException” statement?

And another question:

I’m using the EventHandler to react to exception events. The Developer User’s Guide describes the following:
“When the Event Manager invokes an event handler for an exception event, the event handler receives an IData object …”, see also specification pub.event:exception or doc type pub.event:exceptionInfo. This accords to the output of service pub.flow:getLastError.
Within the ExceptionHandlerService I try to log the error message and the name of the service causing the error, but there is only %serviceName% (variable substitution is enabled) in the log message.

So, does anyone know if getLastError (that is not called in my scenario) has to be explicitly called before or is this done “built-in” by IS?

Thanks in advance for any hints.

Kind regards,
Max.

Hello,
The document template for pub.event:exceptionInfo has service and not serviceName as the field with the invoked service name. You do not need to invoke getLastError in the handler service, and doing so won’t get you any data that is not just an exception that occured in the handler itself. A good test would be to do an immediate savePipelineToFile on a test service so you can see what is populated in the various fields.

For throwing particular excpetions to a parent service, just make sure that the sequence in the separate handler is set to exit-on FAILURE if the catch error should throw as well. an example:

seq exit-on:success## test

  • seq exit-on:failure ## try
    – map ## execute body
  • seq exit-on:done ## catch
    – map ## store exception type
    branch switch:excep ## handler
  • seq label:dividebyzero exit-on:failure ## fatal
    – exit from:flow signal:failure failure-message: x/0 ## let parent know
  • seq label:exit-on done ## transient
    – map ## email a notice

That is one example setup to tell the parent of an error you don’t want to handle or handle entirely. Good day.

Yemi Bedu