api:catch
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
Throw and catch an exception.
Inside an api:call, an APIException 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>