Hi Alex,

I gave the 'catch' a try with '(locale "XY")' in the current (testing) release, and it works great. Thanks a lot!

/Jon

On Tue, May 20, 2008 at 01:37:21PM +0200, Jon Kleiser wrote:
 !? (load (if (setq *Ctry Ctry) (pack "@loc/" @) "@loc/NIL"))
 loc/NO open: No such file or directory

 > Does Pico Lisp have an error handling mechanism that can handle
 errors like this?

Indeed, this is a long-missing feature.

Originally, I intended to introduce it in picoLisp-3.0 (the 64-bit
version). But now I saw that it basically required only a few lines in
the error handler, so I put it into the current (testing) release.


Now you can catch such errors with the normal 'catch' function.

When 'catch' is called with a list of symbols (as opposed to a single
tag symbol, when setting up a catch environment for 'throw'), it will
catch all errors whose messages contain one of these strings as a
substring.

So, if you have an error like

   : (in "doesntExist" (foo))
   !? (in "doesntExist" (foo))
   doesntExist open: No such file or directory
   ?

you can catch it with

   : (catch '("No such file") (in "doesntExist" (foo)))
   -> "No such file"

Note that 'catch' returns the matched substring when it caught such an
error. Therefore, this return value can be used to react appropriately.

   (case
      (catch '("No such file" "Undefined" "expected")
         (doSomething) )
      ("No such file"
         (handleNonExisting File) )
      ("Undefined"
         (handleUndefined Function) )
      ("expected"
         (handleBadArgument Type) )
      (T
         (handleTheCorrectValue @) ) )

The 'T' clause of the above 'case' statement works because '@' holds the
return value of the successful execution of 'doSomething'.

Cheers,
- Alex
--
UNSUBSCRIBE: mailto:[EMAIL PROTECTED]

Reply via email to