throw Statement

Class: Error

Description

This statement enables you to throw an error from any code block or subroutine using PSL. For additional information on throwing errors, refer to the Throwing Exceptions section.

Syntax

To create and throw an error, use the following syntax:

throw Class.new("Error","errorType,

errorDescription,errorContext")

 

To re-throw an existing error object, use the following syntax:

throw errorObject

Parameters

errorType

The exception type (Error.type). To maintain compatibility with future PSL development, the value of this part of the initiation value must conform to the following layout:

component-severity-ident

where:

  • component is free, but the values of %GTM, %PSL, and %SYSTEM are reserved.

  • severity is E, I, or W.

  • ident consists of only uppercase characters and digits.

errorDescription

The exception description (Error.description) (optional).

errorContext

The exception context (Error.context) (optional).

When Became Available

v6.0

Example

catch Error {

    set ET=Error.type

    set CONTEXT=Error.context

    if ET["%GTM" do ZE^UTLERR quit

    set RM=Error.description

    set ET=ET_"-"_RM_"-"_Error.thrownAt

    do ^UTLERR

    }

// throw an application exception

if 'Db.isDefined("DEP",":CID") ...

...throw Class.new("Error","DEP-E-INVLDADT,Invalid account")

else  type RecordDEP dep=Db.getRecord(“DEP”,”:CID”)

________________________________________________________________

Output in the SCAER Report:

 

03/01/2003 DEP-E-INVLDADT-Invalid account-ZERROR1+11^ZERROR1

 

* Variable CID must be defined prior to the isDefined statement

*The Db.isDefined statement should be coded on a single line