Implementing Exception Handling
Use
In a Guided Procedures (GP) process you can create actions that handle exceptions raised by callable object execution. Additionally, you can choose a strategy to repeat or skip the activity that caused the exception.
Prerequisites
- You have instantiated the IGPDesigntimeUpdateManager .
- You have familiarized yourself with the implementation of development objects with the GP design time API.
- You have created a block.
See Creating Blocks .
Procedure
- Create a callable object and define an exception for it.
| Creating a Callable Object with Process Exception |
|---|
importcom.sap.caf.eu.gp.co.api.IGPCallableObject; importcom.sap.caf.eu.gp.process.dt.api.IGPDesigntimeUpdateManager; importcom.sap.caf.eu.gp.co.api.IGPPhysicalCallableObject; // create a callable object IGPCallableObjectco = manager.createCallableObject( coType, locale, coTitle, coDescription, cat.getID() ); // retrieve the physical callable object IGPPhysicalCallableObject pco= co.resolvePhysicalCallableObject(); // define one process exception "e" pco.addProcessException("e","E");
// save and activate the object manager.save(co); manager.activate(co); |
For more information on how to create callable objects, see Creating Callable Objects .
- Insert the callable object into an action and add the action to the block structure.
| Inserting the Callable Object into Action and Block |
|---|
import com.sap.caf.eu.gp.process.api.IGPModifiableAction;import com.sap.caf.eu.gp.process.api.IGPModifiableBlock;
// set execute callable object co to action a_2 a_2.setExecuteCallableObject(co); manager.save(a_2); // add a_2 to the block structure b.getModifiableStructure().addItem(a_2); |
For more information on how to create actions, see Creating Actions .
- Create an exception handling action.
During process execution, the callable object that you created may raise a process exception. You need a mechanism to handle this exception. For this purpose you create an additional action, which determines the processing strategy and informs the user about possible problems.
This action is executed whenever such an exception is raised. Its implementation is standard:
| Creating an Exception Handling Action |
|---|
//define action for the exception handler IGPModifiableActionae = manager.createAction( locale, "ae", "ae description", cat.getID() ); // save and activate the action manager.save(ae); manager.activate(ae); |
- Assign the exception handling action to the block structure item corresponding to the action with the process exception.
| Setting the Exception Handler |
|---|
importcom.sap.caf.eu.gp.process.api.IGPModifiableBlockStructureItem; importcom.sap.caf.eu.gp.process.api.GPExceptionHandlingStrategy; // retrieve block structure item of action a_2 IGPModifiableBlockStructureItemia_2 = b.getModifiableStructure().getModifiableItem(1); // create exception handler on ia_2 ia_2.setExceptionHandler("e",GPExceptionHandlingStrategy.STRATEGY_CONTINUE, ae);
|
The example above also specifies the processing strategy after the exception handling action has been executed. The strategies you can choose from are:
-
STRATEGY_CONTINUE
- process flow continues with the next item in the structure -
STRATEGY_REPEAT
- process flow repeats the item that caused the exception