Error! values represent specialized object! values used for error conditions. Error values contain a fixed number of words (fields) that are defined in system/standard/error.
SYSTEM/STANDARD/ERROR is an object! with the following words and values:
code none! none
type none! none
id none! none
arg1 none! none
arg2 none! none
arg3 none! none
near none! none
where none! none
stack none! noneError! is a member of the following typesets: any-object!, default!
<error> ::= make error! <error-spec>
<error-spec> ::= <integer> | <block> | <string>-
MakeIf the argument supplied to
makeis aninteger!value, the error is looked up by the error typescodefield. The error message will be thestring!value of the firstidfield in the list ofidnames.SYSTEM/CATALOG/ERRORS/MATH is an object! with the following words and values: code integer! 400 type string! "Math Error" zero-divide string! "attempt to divide by zero" overflow string! "math or number overflow" positive string! "positive number required" >> make error! 400 *** Math Error: attempt to divide by zero ; id is the word zero-divide *** Where: ???
To access any of the remaining error messages, increment the error type
codeby one.>> make error! 401 *** Math Error: math or number overflow *** Where: ??? >> make error! 402 *** Math Error: positive number required *** Where: ???
Accessing an error message position that does not exist results in a "value out of range" error.
>> make error! 403 *** Script Error: value out of range: 403 *** Where: make *** Stack:
If the argument supplied to
makeis ablock!value, the block must contain two words that map to thetypeandidof the error.If the argument supplied to
makeis anobject!body, the required fields aretypeandid. Optional fields arearg1,arg2,arg3,near,where, andstack.Use the following words for the
typevalue in an error object.:throw,note,syntax,script,math,access,user,internalYou can find the Ids for the available error types by entering
help system/catalog/errors/<error-type>in the Red console, where<error-type>is one of the above mentioned words.>> help system/catalog/errors/throw SYSTEM/CATALOG/ERRORS/THROW is an object! with the following words and values: code integer! 0 type string! "Throw Error" break string! "no loop to break" return string! "return or exit not in function" throw block! length: 2 ["no catch for throw:" :arg1] continue string! "no loop to continue" while-cond string! {BREAK/CONTINUE cannot be used in WHILE condition block}
Using a block value with two words:
>> make error! [throw type] ; type is the word throw, id is the word type *** Throw Error: Throw Error *** Where: ??? >> make error! [throw break] ; type is the word throw, id is the word break *** Throw Error: no loop to break *** Where: ??? >> make error! [throw while-cond] ; type is the word throw, id is the word while-cond *** Throw Error: BREAK/CONTINUE cannot be used in WHILE condition block *** Where: ???
Using an object body:
>> make error! [type: throw Id: throw arg1: "foo"] *** Throw Error: no catch for throw: "foo" *** Where: throw *** Stack:
>> make error! [type: 'script id: 'move-bad arg1: "foo" arg2: "bar" where: 'somewhere?] *** Script Error: Cannot MOVE elements from "foo" to "bar" *** Where: somewhere?
Using a
string!value:If the argument supplied to
makeis astring!value, the error type will beUser Error.>> foo: make error! "oops" *** User Error: "oops" *** Where: ???
-
Cause-errorCause-errorcallsmake error!withtype,id, and a block of values forarg1,arg2, andarg3. If an error message contains no arg values, supply an empty block.>> cause-error 'throw 'break [] *** Throw Error: no loop to break *** Where: do *** Stack: cause-error
Arg values in the block are reduced.
>> cause-error 'syntax 'missing ['foo 'bar] *** Syntax Error: missing foo at bar *** Where: do *** Stack: cause-error >> cause-error 'syntax 'missing ["foo" "bar"] *** Syntax Error: missing "foo" at "bar" *** Where: do *** Stack: cause-error
Use error? to check if a value is of the error! datatype.
>> error? foo
== trueUse type? to return the datatype of a given value.
>> type? foo
== error!