Thrown Fault with Catch
Thrown Fault with Catch
A thrown fault may reach a <catchall>, as in the previous example, or it may have a specific <catch>.
Suppose you have the following BPL:

This BPL business process does the following:
-
The first <trace> element generates the message before scope.
-
The <scope> element starts the scope.
-
The second <trace> element generates the message before throw.
-
The <throw> element throws a specific, named fault ("MyFault").
-
Control now goes to the <faulthandlers> defined within the <scope>. The <scope> rectangle includes a horizontal dashed line across the middle; the area below this dashed line displays the contents of the <faulthandlers> element. In this case, a <catch> element exists whose fault value is "MyFault", so control goes there. The <catchall> element is ignored.
Note that InterSystems IRIS skips the <trace> element message after the <throw> element.
If we drill down into <catch>, we see this:
Note:If a <catchall> is provided, it must be the last statement in the <faulthandlers> block. All <catch> blocks must appear before <catchall>.
-
Within <catch>, the <trace> element generates the message in catch faulthandler for ‘MyFault’.
-
The <scope> ends.
-
The last <trace> element generates the message after scope.
Event Log Entries
The corresponding Event Log entries look like this:

XData for This BPL
This BPL is defined by the following XData block:
XData BPL
{
<process language='objectscript'
request='Test.Scope.Request'
response='Test.Scope.Response' >
<sequence>
<trace value='"before scope"'/>
<scope>
<trace value='"before throw"'/>
<throw fault='"MyFault"'/>
<trace value='"after throw"'/>
<faulthandlers>
<catch fault='"MyFault"'>
<trace value='"In catch faulthandler for 'MyFault'"'/>
</catch>
<catchall>
<trace value='"in catchall faulthandler"'/>
<trace value=
'"%LastError "_
$System.Status.GetErrorCodes(..%Context.%LastError)_
" : "_
$System.Status.GetOneStatusText(..%Context.%LastError)'
/>
<trace value='"%LastFault "_..%Context.%LastFault'/>
</catchall>
</faulthandlers>
</scope>
<trace value='"after scope"'/>
</sequence>
</process>
}