Previous Page | Next Page

SAS Component Language Dictionary

THROW



Raises an exception
Category: Control Flow

Syntax
Details
Example
See Also

Syntax

THROW exception;

exception

is the local variable for the exception that you want to process.


Details

All exceptions are subclasses of the SCL Exception class. You can use the CLASS statement to define your own exception classes, and then use THROW statements to raise the exceptions.

When an exception is thrown, normal execution of the SCL entry stops, and SCL begins looking for a CATCH block to process the exception.

Note:   You must always declare a variable to hold the thrown exception.  [cautionend]


Example

The following class defines a subclass of SCLException called NewException, which defines an attribute named SecondaryMessage:

Class NewException extends SCLException;
   dcl string SecondaryMessage;
endclass;

You can create a new instance of NewException and raise this exception with the THROW statement, as shown here in the ThrowIt class:

Class ThrowIt;
  m: method;
  dcl NewException NE = _new_ NewException('Exception in method m');
  NE.SecondaryMessage = "There's no code in m!";
  throw NE;
  endmethod;
endclass;


See Also

CATCH

Handling Exceptions

Previous Page | Next Page | Top of Page