This document details the procedure in defining exceptions in a method and using the same in a workflow.
Let us first look at raising exceptions in a method:
Go to Business Object Builder (Transaction SWO1).
Create a business object.
Now create a method.
Now select the method you have created and click on button “Exceptions” available on the toolbar.
Following screen appears:
Now click on Create. Following popup screen appears:
Enter the information as shown above. The error type “Temporary error” is chosen in the case wherein the record is locked by somebody else or some required resource is not available. The error type “Application Error” is to be chosen when there is no authorization for the document you are processing. The error type “System error” is to be chosen if there are no values passed for the mandatory parameters.
Click on continue.
Go back to the main screen.
Now in the method, provide the following code:
Save the business object and release the same.
Try executing the method by clicking on Test/Execute (F8). The exception would be raised as shown below:
Capturing the exception raised by the method in the workflow:
Go to Workflow Builder (TCode: SWO1).
Create the step “Activity”
Create a task and provide the following details in the new task:
Save your entries and return to the previous screen.
Click on “Outcomes” tab. Here you can observe the exception you defined in your method:
As observed in the observe screen, the outcome is not active by default. If we do not handle the exception, the work item might go into the error status. Activate the outcome:
Save your entries and go back to the main screen of Workflow builder. Please ensure that you have done the agent assignment for this task.
You can now observe a new branch when the exception is raised. You can define your steps whenever the exception is raised.