Caché MultiValue Basic Reference
CATCH
|
|
Identifies a block of code to execute when an exception occurs.
Synopsis
TRY
statements
CATCH [exceptionvar]
statements
END TRY
The
CATCH statement defines an exception handler, one or more statements to execute when an exception occurs in the code following a
TRY statement. The
CATCH statement is followed by one or more exception handling code statements. The
CATCH block must immediately follow its
TRY, and the paired
TRY and
CATCH are terminated by an
END TRY statement.
The
CATCH statement has two forms:
CATCH without an Argument
Argumentless
CATCH is invoked when an exception occurs in the
TRY block. This executes the series of statements between
CATCH and
END TRY.
CATCH exceptionvar is invoked when an exception occurs in the
TRY block. This exception passes
exceptionvar to the
CATCH block. This exception can either be explicitly invoked by a
THROW statement, or issued by the system runtime environment in the event of a system exception. The
exceptionvar Caché Object reference (oref) provides properties that contain information about the exception, such as the Name of the error and the Location where it occurred. The user-written
CATCH exception handler code can use this information to analyze the exception.
The following example shows a
CATCH invoked by a runtime exception. The
myvar argument receives a system-generated exception object:
TRY
PRINT "about to divide by zero"
a=7/0
PRINT "this should not display"
CATCH myvar
PRINT "this is the exception handler"
PRINT :myvar->Name,"Error Name"
PRINT :myvar->Code,"Error Code Number"
PRINT :myvar->Location,"Error Location"
END TRY
PRINT "this is where the code falls through"