REBOL 3 Docs Guide Concepts Functions Datatypes Errors
  TOC < Back Next >   Updated: 3-Aug-2010 Edit History  

REBOL 3 Functions: disarm

disarm  value

Deprecated function for converting error objects. Not used in R3.

Arguments:

value [any-type!]

See also:

error?   try   attempt  

Description

Not used in R3

The disarm function is not used in R3. That's because the error! datatype is not "hot" like it is in R2. In R3, it acts like other datatypes, and can be set to variables, passed to functions, and returned as results without triggering a throw exception.

Description for R2

DISARM allows access to the values of an error object. If the error is not disarmed, it will occur again immediately.

probe disarm try [1 + "x"]
make object! [
code: 308
type: 'Script
id: 'cannot-use
arg1: 'add
arg2: string!
arg3: none
near: [+ "x"]
where: [+ try do attempt if emit parse foreach catch if either if do begin do]

]

The error object returned from DISARM can be used to determine the type of error and its arguments. For example in the case of a divide by zero error:

probe disarm try [1 / 0]
make object! [
code: 400
type: 'Math
id: 'zero-divide
arg1: none
arg2: none
arg3: none
near: [/ 0]
where: [/ try do attempt if emit parse foreach catch if either if do begin do]

]

You might write a TRY block that handles the error after it has happened:

if error? err: try [
    value: 1 / 0
][
    err: disarm err
    either err/id = 'zero-divide [value: 0] [probe err quit]
]
print value
0


  TOC < Back Next > REBOL.com - WIP Wiki Feedback Admin