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

[REBOL] Error handling

From: lmecir::mbox::vol::cz at: 3-Jul-2004 8:10

Hi all (esp. Gabriele), I thought once more about error handling. It looks, that it may be useful to be able to specify the error variable like below: default: func [ {Execute code. If error occurs, execute fault.} [throw] code [block!] {Code to execute} error [word!] {The error variable} fault [block!] {Error handler} ] [ either error? set/any 'code try code [ do make function! reduce [[throw] error [error!]] fault code ] [get/any 'code] ] comment [; Usage/tests: ex1: function [[catch]] [r] [ set/any 'r throw-on-error a do b ] ex2: function [[catch]] [r] [ if none? set/any 'r attempt a [ throw make error! "error" ] do b ] ex3: function [[catch]] [r] [ set/any 'r default a 'error [throw error] do b ] a: [return "OK"] b: ["KO"] ex1 ex2 ex3 a: [()] b: [if not value? 'r ["OK"]] ex1 ex2 ex3 a: [none] b: ["OK"] ex1 ex2 ex3 ]