[REBOL] RWT: Error handling
From: maarten::koopmans::surfnet::nl at: 3-Mar-2003 19:42
REBOL
[
Title: "Error handling code"
]
handle: func
[
{Executes a code block with optional error handling.}
[catch]
code [ any-block!] {The code to be evaluated}
/with {Specify a code block that acts as an error handler.}
handler [block!] {The code block that handles the error.}
/pass-to {Specify a function that acts as an error handler. A
disarmed error is passed to this function, so it must
expect a single object argument.}
f [function!] {The function that handles the error.}
/pass-params {Pass optional parameter block to the error handler.}
params [block!] {Block containing parameters.}
/transparent {Rethrows any caught error after executing the handler(s).}
/local result disarmed
]
[
; Try to execute the code.
if error? set/any 'result try code
[
; If an error occurs, handle it in accordance with the refinements,
; otherwise, return the value returned by the code block
disarmed: disarm result
; Do we have a handler function?
if pass-to
[
either pass-params [ f disarmed params ][ f disarmed ]
]
; Is there a code block to handle the error?
if with
[
bind handler 'disarmed
do handler
]
; Optionally rethrow the error.
if transparent
[
result
]
return none
]
get/any 'result
]