For Dexterity-based applications, exceptions are divided into two categories. User exceptions are illegal or inappropriate situations that are specific to a single application, such as a data value being outside of an acceptable range. System exceptions are error situations that can occur in any Dexterity-based application, such as a division-by-zero error or a form not being found in a dictionary.
To implement structured exception handling in a Dexterity application, use the try...end try statement. The try clause indicates that a series of sanScript statements will be executed. As the statements are executed, any exception that occurs is thrown back to the exception handler to be dealt with. The throw statement is used to throw user exceptions. System exceptions are thrown automatically.
The exception handler contains catch clauses to handle specific exceptions that are thrown. An else clause can be included to handle exceptions that aren’t specifically caught. An unhandled exception occurs when an exception isn’t caught and there is no else clause for the try statement. When an unhandled exception occurs, a message is automatically displayed that describes the situation to the user.
The following illustration shows the basic structure of an exception handler.