Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

[REBOL] Re: global error handling?

From: greggirwin:mindspring at: 25-Jul-2003 10:29

Hi Max, MOA> is there a way to handle an error globaly by putting a "hook" or MOA> appending to a block somewhere deep in the system funcs. Below is something Brett cooked up, which might give you some ideas. -- Gregg REBOL [ Author: "Brett Handley" Date: 22-Jan-2003 Comment: "To simulate Gregg's idea of an insert-error-func system." ] system/error: make system/error [ error-funcs: copy [] detect: func [ [catch] error [error!]] [ foreach evt-func error-funcs [ if not error? evt-func: evt-func error [ return either evt-func [error] [none] ] ] error ] ] insert-error-func: func [ {Add a function to monitor global errors. Return the func.} funct [block! function!] "A function or a function body block" ] [ if block? :funct [funct: func [error [error!]] funct] insert system/error/error-funcs :funct :funct ] remove-error-func: func [ "Remove an error function previously added." funct [function!] ] [ remove any [find system/error/error-funcs :funct ""] ] app-wait: has [result] [ forever [ if not error? set/any 'result try [wait []] [break] system/error/detect result ] ] ; ---- Example Application insert-error-func [ error: disarm error if block? msg: get in get in system/error error/type error/id [ msg: bind/copy msg in error 'self ] alert reform msg false ] view/new layout [ button "Divide by zero" [1 / 0] button "Read %/h/test" [read %/h/test] ] app-wait