Trapping an error
[1/4] from: Steven:White:ci:bloomington:mn:us at: 7-Nov-2003 9:05
I am wondering if someone can tell me how to trap a particular error. Yes, I have read the GDM, on "try" and "attempt," but they don't seem to be the correct answer. (It is quite possible I don't fully understand the documentation.) Here is the situation: I have a "configuration file" for a script. The configuration file is itself a little REBOL script that just sets the values of some words, for example REBOL [ File: %config.r ] HELP-FILENAME: %XXXXXX In the main script, I set default values for those things in the configuration file, and then "do" the configuration file to over-ride the default values. For example REBOL [ File: %main.r ] HELP-FILENAME: %YYYYY ;;; set default value do %config.r ;;; override default value This works just fine EXCEPT if I put an incorrectly-formatted file name in the configuration file. If the file name in the configuration file is bad, then when I "do" that file the script crashes. Is there a way to trap that error before the REBOL interpreter does, so that I can handle the error in my own way? Thank you. Steven White City of Bloomington 1800 W Old Shakopee Rd Bloomington MN 55431-3096 USA 952-563-4882 (voice) 952-563-4672 (fax) [steven--white--ci--bloomington--mn--us]
[2/4] from: SunandaDH:aol at: 7-Nov-2003 10:37
> HELP-FILENAME: %YYYYY ;;; set default value > do %config.r ;;; override default value > > This works just fine EXCEPT if I put an incorrectly-formatted file name > in the configuration file. If the file name in the configuration file > is bad, then when I "do" that file the script crashes.
Maybe I'm missing the point here, but... if error? capture-error: try [do %config.r] [ print ["Whoops! " mold disarm capture-error] ] ...should do the trick There are some REBOL errors that crash the interpretor entirely and don't get trapped, but a badly formed file name shouldn't be one as far as I know. Just for interest, one such error (it'll crash 188.8.131.52.1 REBOL) is: aa: make object!  bb: make object! aa The second line should be: bb: make aa  Sunanda.
[3/4] from: g:santilli:tiscalinet:it at: 7-Nov-2003 16:46
Hi Steven, On Friday, November 7, 2003, 4:05:09 PM, you wrote: SW> REBOL [ SW> File: %main.r SW> ] SW> HELP-FILENAME: %YYYYY ;;; set default value SW> do %config.r ;;; override default value If you are not interested in what the error is, you can just use: attempt [do %config.r] If you want to know what error happened, etc., you can use something like: if error? set/any 'error try [do %config.r] [ print mold disarm error ] I am using "set/any 'error ..." instead of "error: ..." because the former works even if "do %config.r" does not return anything. Regards, Gabriele. -- Gabriele Santilli <[g--santilli--tiscalinet--it]> -- REBOL Programmer Amiga Group Italia sez. L'Aquila --- SOON: http://www.rebol.it/
[4/4] from: lmecir::mbox::vol::cz at: 7-Nov-2003 17:10
Hi Sunanda, this is worth a record at the R.E.P. site -L ...