THROW Verb

Syntax

THROW str{,int}{,ERR=lineref}

Description

In BBj 6.0 and higher, the THROW verb generates a runtime error with a given error message and a given error number.

Parameter

Description

str

The value returned by errmes(-1)after the runtime error has been generated.

int

The value returned by err after the runtime error has been generated. It must evaluate to a non-negative integer value in the range [0,1024].

ERR=lineref

In BBj 18.0 and higher, an ERR= may be specified to immediately take the specified branch, as opposed to throwing the error to the error handler in effect.

Remarks

BASIS reserves the error numbers in the range 0-255. While developers can "throw" these BASIS-reserved error numbers, they should avoid attaching any private meaning to any error number in this reserved range as BBj might generate an error number in this range at some future time.

The error numbers in the range 256-1024 are reserved for developer use. BASIS will not use any numbers in this range so developers can attach whatever meaning they want to the numbers in this range.

THROW will not allow the developer to throw an error number that is above 1024. Attempting to THROW an error number above 1024 will result in !ERR=202 (BBJ_ILLEGAL_USAGE).

Examples

rem 'disallow break to console in call program

options$ = opts
options$(1,1) = and(options$(1,1),$f7$)
setopts options$

rem 'set an error handler
seterr errorHandler

rem 'call this program at label:
A$=pgm(-2) + "::label"
call A$
escape

rem 'do a THROW
label:
    throw "custom error message", 256
end

errorHandler:
    print "received error:",err, " message: ",errmes(-1)
    escape

See Also

STBL Formats - BBj

STBL("!THROWERROR")

BBjConfig::setOptionSetting

Verbs - Alphabetical Listing