How do I Handle Faults?

A fault is an error or failure. When a fault occurs, fault handling provides a means of error handling, including backing out the unsuccessful or incomplete work of an activity by transferring control to the fault handler that you defined.

You can create fault handlers for three different types of faults:

Catching Faults

You can throw faults and you can catch faults. Faults can happen at any time and you can catch them using fault handlers on Invoke activities, Scopes, or at the process level.

To add a fault handler to your process:

  1. In the BPEL Editor, decide where you want to place the fault handler within the process, right-click and select Add Fault Handler. You can add fault handlers to Invoke activities, Scopes, or at the process level.

    The fault handler template displays which you can use to configure the fault handler.
    Adding fault handers
  2. To configure the fault handler, click the Catch element in the fault handler template.

    You can now interact with the Catch Properties view.
  3. Select the Fault Type for the fault you are going to catch: Service, User-defined, or Standard BPEL.
    In the Web Service Explorer, which you use to test your service, it is easy to determine the fault you are working with by forcing your service to fail. This is usually done by supplying invalid input to the process. In the Status pane, note the fault type.

    Fault type

  4. The Fault Name drop down list provides a complete list of the faults that can originate from the current process or scope. In the example in Step 3 it is a user fault, but it can be any fault available from the drop down list.
    Fault type
  5. The variable name is the name of the local variable that is automatically created and that contains the fault information. This is useful to extract information about the fault that occurred, which you will walk through in the following steps. The structure of the fault shows you want the fault looks like.
  6. The next step is to make sure you can return output to the user. Depending on your own circumstances this process will vary. In many cases you will want to add your own logic by means of an Assign and copy rule. These instructions assume that scenario.
  7. To send the response back to the user, add a Reply activity and configure it for an output using the Quick Pick panel in the Properties view.

    Quick Pick
  8. You can add other catches for other faults in the service by following the same process.
  9. Deploy to the Process Server to test using the Web Services Explorer.

Throwing Faults

You can throw and catch your own faults by using the Throw and Catch activities from the Palette. This procedure is very similar to the one for catching faults.

  1. From the palette, drag a Throw activity to the process diagram wherever you want to throw a fault. This is just a sample illustration.
    Throw
    The Properties view for the Throw activity is very similar to the one described in the Catching Faults section and you interact with it similarily.
  2. Choose your own fault name and optionally click Browse to create your own fault variable. The fault variable defines the structure of the fault. This is optional. If you decide to do this you can use the Schema Editor to define the structure of the variable, create a highly specific error, throw it, and later catch it.
  3. Create a fault handler to catch your fault. As in step 2 above, add a fault handler and define the fault handling logic using the copy rule dialog box.
Related Topics
Bullet Throw Activity
Bullet Standard BPEL Faults