Exception Handling

Top  Previous  Next


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




!Statement which can cause an exception.

CATCH(Exception e)

!Statements for handling the exception


!Any cleanup code here




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)

TRY-CATCH-FINALLY (exception handling block)