| **Navigation:**  [[clarion.htm|Clarion.Net (Clarion#)]] > [[clarion net language reference.htm|Clarion# Language Extensions]] > Exception Handling >====== Exception Handling ====== | [[foreach arrayed looping construct .htm|{{btn_prev_n.gif|Previous page}}]][[clarion net language reference.htm|{{btn_home_n.gif|Return to chapter overview}}]][[throw signal an exception .htm|{{btn_next_n.gif|Next page}}]] | | || {{newcnet.jpg|NewCNet.jpg}} Exception handling is a built in mechanism in the Clarion# framework to detect and handle run time errors. The .NET framework contains lots of standard exceptions. The exceptions are anomalies that occur during the execution of a program. They can be because of user, logic or system errors. If a user (programmer) do not provide a mechanism to handle these anomalies, the .NET run time environment provide a default mechanism, which terminates the program execution. Clarion# provides three keywords to do exception handling. **TRY** is a structure that encloses the statements that might throw an exception. **CATCH** handles an exception if one exists. **FINALLY** is used for doing any clean up process. The general form of TRY-CATCH-FINALLY in Clarion# is shown below **TRY** ** !Statement which can cause an exception.** **CATCH(Exception e)** ** !Statements for handling the exception** **FINALLY** ** !Any cleanup code here** **END** If any exception occurs with TRY, the control transfers to the appropriate CATCH section, and later to the FINALLY section. CATCH and FINALLY are optional. TRY can exist either with one or more CATCH statements or a single FINALLY statement, or with both. If there is no exception inside the TRY section, control directly transfers to the FINALLY statement. Statements following FINALLY is executed always. Note that it not recommended to transfer control out of a FINALLY section using BREAK, RETURN or GOTO. [[throw signal an exception .htm|THROW (signal an exception)]] [[try arm exception handling .htm|TRY-CATCH-FINALLY (exception handling block)]]