Caché MultiValue Basic Reference
[Home] [Back] [Next]
InterSystems: The power behind what matters   
Class Reference   

Throws an exception from a TRY block to a CATCH exception handler.
THROW [oref]
oref Optional — A user-defined object reference.
The THROW statement explicitly issues an exception from within a block of code defined by a TRY statement. Issuing a THROW transfers execution from the TRY block to the corresponding CATCH exception handler.
THROW is used to issue an explicit exception. MVBasic issues an implicit exception when a runtime exception occurs. A runtime exception generates an exception object which it throws to a CATCH exception handler.
THROW has two forms:
THROW without an Argument
Argumentless THROW transfers exception processing to the corresponding CATCH exception handler. No object is pushed on the stack, but the %New() method is called.
THROW with an Argument
THROW oref specifies a user-defined object reference, which it throws to the CATCH statement.
A user-defined object reference (oref). For example, THROW "Sample.MyException"->%New("Example Error",45). The creation and population of this exception object is the responsibility of the programmer.
The following example shows the use of THROW:
    PRINT "about to issue a THROW statement"
    THROW "Sample.MyException"->%New("Example Error",45,"Sample Program")
    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"
  PRINT "this is where the code falls through"
See Also