do // regular code on Exception // exception handling code on exit // clean-up code (always executed) end
The do-end block, though not required, allows you to clearly define the scope of an exception within your code. This is particularly important if you need to nest exceptions within multiple do-end blocks.
The on Exception statement allows you to define the block of code that executes only if the exception is raised.
The on exit statement allows you to perform any clean up operation and releasing resources. This can include cleaning up temporary systems files or database table created within your PBL code. This block is always executed, whether an Exception was raised or not.
The following code example demonstrates the syntax for using the on Exception and on Exit constructs.
on TooCloseToDueDateException do
sendAlert project
using mailSubject = project.name + "is getting too close to due date",
mailMessage = "The project " + project.name + "is getting to cloose to due date."
on OverdueException do
sendAlert project
using mailSubject = project.name + "is overdue",
mailMessage = "The project " + project.name + "is overdue."
on exit do
sendAlert project
using mailSubject = "Work on project " +project.name + " was started.",
mailMessage = "Work on project " + project.name + " was started on " + project.startDate
+ ". The project leader for is: " + project.projectLeaderId
end
This example uses the default PBL programming style. Other programming styles use different keywords for exception handling, but the underlying concept is the same. If you are using the Java programming style, this is implemented within a try-catch block.
See Compound Statements for more information.
In many cases, you may not want to catch exceptions within PBL code. Within your process it may make more sense to let them propagate as process-level exceptions. Any exceptions not explicitly handled within PBL code (with on Exception blocks) are propagated. If an exception cannot be completely resolved within PBL code, it should propagate up as a process-level exception, to be handled with an exception handling process flow.