Sample Guide - Fault Handling

Objective

This sample explains about basic fault handling. In fault handling, <throw/> and <rethrow/> are used to generate faults where faults occurs.

  • <throw/> Faults should be named with a unique scope level qualified name.

    eg -

    <throw faultName="saw:InputException2" />
    
  • <rethrow/> is used only inside <catch/> or <catchAll/> which will be described later in order to re-throw the originally caught exceptions.

    eg -

    <catchAll>
        <rethrow/>
    </catchAll>
    
  • The fault handling is implemented inside <faultHandlers/>. Faults can be handled based on qualified name of the thrown fault using <catch/> or Every non-specified faults can be handled inside <catchAll/>.

    eg -

    <faultHandlers>
        <catch faultName="saw:InputException2">
            <throw faultName="saw:Exception1Handled"/>
        </catch>
        <catchAll>
            <rethrow/>
        </catchAll>
    </faultHandlers>
    

Note - <faultHandlers/> should be defined in a parent scope.


Prerequisites

  • Log in into BPS server admin console.
  • Under Business Processes -> Add BPEL.
  • Upload the TestThrowCatchFaultHandling.zip , (all samples are located at our sample repository.)
  • Under the Business Processes -> Processes.
  • Under the WSDL details widget -> Create instance

Overall Idea

Refer - TestThrowCatchFaultHandling.zip

In the child scope the input value is checked whether it's equal to 1. If so an InputException1 is thrown. Note that the thrown exception has a "saw:InputException1" qualified name.

eg -

<if name="ExceptionCondition1">
    <condition>number($value)=number(1)</condition>
    <throw faultName="saw:InputException1"/>
    <else>
        <throw faultName="saw:TransitionConditionOutOfRangeException1"/>
    </else>
</if>

In the parent scope the exception is filtered against its qualified name.

eg -

<faultHandlers>
    <catch faultName="saw:InputException1">
        <if name="ExceptionCondition2">
            <condition>true()</condition>
            <throw faultName="saw:InputException2"/>
            <else>
                <throw faultName="saw:TransitionConditionOutOfRangeException2"/>
            </else>
        </if>
    </catch>
</faultHandlers>