api:catch

Version 23.4.8843


api:catch

Version 23.4.8843


The api:catch keyword is used to create an exception-handling block in a script. In addition to api:try, you can contain an api:catch block within any of the following keywords, the scope of which serves as an implicit api:try section:

Parameters

  • code: The code parameter allows you to selectively catch exceptions. To catch all exceptions, use the character *.

Control Attributes

  • _code: The code of the caught exception.
  • _desc: A short description of the caught exception.
  • _details: More information about the exception, if available.

Examples

Wrap a more user-friendly message around the error output from a batch file or shell command:

<api:try>
<api:call op="sysExecute">
  <api:check attr="sys:error">
    <api:throw code="myerror" description="Batch file could not be executed" details="[sys:error]"/>
  </api:check>
</api:call>
<api:catch code="*">
  <api:call op="appSendEmail"/>
</api:catch>
</api:try>

Throw and catch an exception. Inside an api:call, an RSBException is thrown and caught. Inside the scope of the keyword, the api:ecode and api:emessage attributes are added to the current item and pushed out.

<api:call op="...">
  <api:throw code="myerror" description="thedescription" details="Other Details."/>
  <api:catch code="myerror">
    <api:set attr="api:ecode" value="[_code]"/>
    <api:set attr="api:emessage" value="[_description]: [_details]"/>
    <api:push/>
  </api:catch>
</api:call>

Catch all exceptions:

<api:catch code="*">
  An exception occurred. Code: [_code], Message: [_desc]
</api:catch>

See Also