User Tools

Site Tools


exception_handling.htm
Navigation:  Clarion.Net (Clarion#) > Clarion# Language Extensions > Exception Handling >====== Exception Handling ====== Previous pageReturn to chapter overviewNext page

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)

TRY-CATCH-FINALLY (exception handling block)

exception_handling.htm.txt · Last modified: 2021/04/15 15:57 by 127.0.0.1