Skip to main content

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:

BPL diagram with several shapes surrounded by a rectangle that has a dashed line in the middle

This BPL business process does the following:

  1. The first <trace> element generates the message before scope.

  2. The <scope> element starts the scope.

  3. The second <trace> element generates the message before throw.

  4. The <throw> element throws a specific, named fault ("MyFault").

  5. 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:

    BPL diagram with the following shapes in order: start, trace, end

    Note:

    If a <catchall> is provided, it must be the last statement in the <faulthandlers> block. All <catch> blocks must appear before <catchall>.

  6. Within <catch>, the <trace> element generates the message in catch faulthandler for ‘MyFault’.

  7. The <scope> ends.

  8. The last <trace> element generates the message after scope.

Event Log Entries

The corresponding Event Log entries look like this:

Event log with entries for before scope, before throw, in catchall faulthandler, and after scope

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 &apos;MyFault&apos;"'/>
        </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>
}
FeedbackOpens in a new tab