Chapter Contents

Previous

Next
CATCH

CATCH



Processes an exception that has been thrown with the THROW statement

Category: Control Flow


Syntax
Details
Example
See Also

Syntax

CATCH exception;
/* SCL statements to process the exception */
ENDCATCH;

Note:   

CATCH blocks must always be enclosed in DO statements.  [cautionend]

exception
is the local variable for the exception (which is an instance of the SCLException class) that you want to process.


Details

When an exception is raised via the THROW statement, normal execution of the program stops, and SCL begins looking for a CATCH block to process the exception. The CATCH block can contain any statements needed to process the exception, including additional CATCH and THROW statements.

SCL uses the scope of the DO group that contains the CATCH block and the class of the exception to determine which CATCH block to execute. For details, see How SCL Determines Which CATCH Block To Execute.

Each entry in the stack can process an exception and then pass it back up the stack by rethrowing it, which allows the calling entry to perform additional processing. Each entry can perform whatever processing is relevant to that entry.

If an exception is rethrown within a CATCH block, no other CATCH block within the same scope can recatch the exception. The exception is passed out of the scope where it was thrown. Also, you cannot define multiple CATCH blocks for the same exception within the same scope.


Example

The following DO group declares a local exception variable called NE, creates a new instance of NE, and throws the new exception. The CATCH block prints the traceback information that is automatically stored by SCL when an exception is thrown.

do;
dcl SCLException NE = _new_ NewException('Exception in method m'); 
throw NE; 

catch NE;
   put NE.getMessage();         /* Print exception information. */
   call putlist(NE.traceback);
endcatch;
end;

See Also

THROW

Handling Exceptions


Chapter Contents

Previous

Next

Top of Page

Copyright 1999 by SAS Institute Inc., Cary, NC, USA. All rights reserved.