Chapter Contents

Previous

Next
THROW

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 SCLException 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


Chapter Contents

Previous

Next

Top of Page

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