REBOL 3 Docs Guide Concepts Functions Datatypes Errors
  TOC < Back Next >   Updated: 6-Feb-2009 Edit History  

REBOL 3 Concepts: Errors: Error Object

Pending Revision

This document was written for R2 and has yet to be revised for R3.

The error object shown above has the structure:

make object! [
    code: 400
    type: 'math
    id: 'zero-divide
    arg1: none
    arg2: none
    arg3: none
    near: [100 / 0]
    where: none

Where the fields are:

codeThe error code number. These are obsolete and should not be used.
typeThe type field identifies the error category. It is always a word datatype of syntax, script, math, access, user, and internal.
idThe id field is the name for the error as a word. It identifies the specific error that occurred within the error category.
arg1This field holds the first argument to the error message. For instance, it may include the datatype of the value that caused the error.
arg2This field holds the second argument to the error message.
arg3This field holds the third argument to the error message.
nearThe near field is a code fragment that shows where the error occurred.
whereThe where field is reserved.

You can write code that checks any of the error object fields. In this example, the error is printed only when the error id indicates a divide by zero error:

error: disarm try [1 / 0]
if error/id = 'zero-divide [
    print {It is a Divide by Zero error}
It is a Divide by Zero error

The error id word also provides the error block that will be printed by the interpreter. For example:

error: disarm try [print zap]
probe get error/id
[:arg1 "has no value"]

This block is defined by the system/errors object.

  TOC < Back Next > - WIP Wiki Feedback Admin