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

Error handling

 [1/7] 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 ]

 [2/7] from: g:santilli:tiscalinet:it at: 3-Jul-2004 11:40


Hi Ladislav, On Saturday, July 3, 2004, 8:10:19 AM, you wrote: LM> comment [; Usage/tests: LM> ex1: function [[catch]] [r] [ LM> set/any 'r throw-on-error a LM> do b LM> ] LM> ex2: function [[catch]] [r] [ LM> if none? set/any 'r attempt a [ LM> throw make error! "error" LM> ] LM> do b LM> ] LM> ex3: function [[catch]] [r] [ LM> set/any 'r default a 'error [throw error] LM> do b LM> ] LM> a: [return "OK"] LM> b: ["KO"] LM> ex1 LM> ex2 LM> ex3 LM> a: [()] LM> b: [if not value? 'r ["OK"]] LM> ex1 LM> ex2 LM> ex3 LM> a: [none] LM> b: ["OK"] LM> ex1 LM> ex2 LM> ex3 LM> ] Hmm, I guess 'R should actually be global in the examples above? Regards, Gabriele. -- Gabriele Santilli <[g--santilli--tiscalinet--it]> -- REBOL Programmer Amiga Group Italia sez. L'Aquila --- SOON: http://www.rebol.it/

 [3/7] from: lmecir:mbox:vol:cz at: 3-Jul-2004 12:31


Gabriele Santilli napsal(a):
>Hi Ladislav, >On Saturday, July 3, 2004, 8:10:19 AM, you wrote:
<<quoted lines omitted: 32>>
>Regards, > Gabriele.
No, it should be as it is to show what *does* and what *doesn't* work as expected. -L

 [4/7] from: g:santilli:tiscalinet:it at: 3-Jul-2004 21:12


Hi Ladislav, On Saturday, July 3, 2004, 12:31:18 PM, you wrote: LM> No, it should be as it is to show what *does* and what *doesn't* work as LM> expected. I'm referring to this case: a: [()] b: [if not value? 'r ["OK"]] ex1 ex2 ex3 which gives "OK" for EX2. How can you check for 'R in B if 'R is local to the EX functions while the 'R in B is global? Either you should bind B in the EX functions or leave 'R global... Unless you really wanted EX2 to be "OK" in this case, but then I wonder why it should be an example of something that does not work as expected. ;-) Regards, Gabriele. -- Gabriele Santilli <[g--santilli--tiscalinet--it]> -- REBOL Programmer Amiga Group Italia sez. L'Aquila --- SOON: http://www.rebol.it/

 [5/7] from: lmecir:mbox:vol:cz at: 4-Jul-2004 8:03


Gabriele Santilli napsal(a):
>Hi Ladislav, >On Saturday, July 3, 2004, 12:31:18 PM, you wrote:
<<quoted lines omitted: 14>>
>Regards, > Gabriele.
Hi, this example may look strange, but normally (for undefined global 'r): do b ; == "OK" and both Ex2 and Ex3 yield this as opposed to Ex1, which doesn't work as expected. -L

 [6/7] from: lmecir:mbox:vol:cz at: 4-Jul-2004 8:28


Ladislav Mecir napsal(a):
>Hi, > >this example may look strange, but normally (for undefined global 'r): > > do b ; == "OK" > >and both Ex2 and Ex3 yield this as opposed to Ex1, which doesn't work as >expected. > >-L >
I found out, that you were right, I changed b to b: ["OK"] to simplify things. -L

 [7/7] from: g:santilli:tiscalinet:it at: 4-Jul-2004 10:22


Hi Ladislav, On Sunday, July 4, 2004, 8:03:09 AM, you wrote: LM> and both Ex2 and Ex3 yield this as opposed to Ex1, which doesn't work as LM> expected. But EX2 would not yield "OK" if 'R was global --- wasn't this the problem you wanted to outline with using ATTEMPT in these cases? Anyway, not an important issue, really. :) Regards, Gabriele. -- Gabriele Santilli <[g--santilli--tiscalinet--it]> -- REBOL Programmer Amiga Group Italia sez. L'Aquila --- SOON: http://www.rebol.it/

Notes
  • Quoted lines have been omitted from some messages.
    View the message alone to see the lines that have been omitted