Subject: Re: parsing a string
From: rpw3@rpw3.org (Rob Warnock)
Date: Fri, 09 Jul 2004 03:15:01 -0500
Newsgroups: comp.lang.lisp
Message-ID: <LPydndjQSpOYyXPdRVn-hQ@speakeasy.net>
Frank Buss  <fb@frank-buss.de> wrote:
+---------------
| But I can change my format. If I use a Lisp-like string:
|   (("key1" . "value1") ("key2" . "value2") ("key1" . "but another value") 
|   ("empty" . "") ("key3" . "foo"))
| it is really simple to parse it, using read-from-string, but how can I 
| catch an error? I've tried this:
|   (handler-bind ((error #'(lambda (c) nil))) (read-from-string "("))
| but it shows the debugger instead of returning nil.
+---------------

For something that simple, just use HANDLER-CASE:

    > (handler-case
	  (read-from-string "(")
	(error (c)
	  (declare (ignore c))
	  nil))

    NIL
    > 

or even just IGNORE-ERRORS:

    > (ignore-errors (read-from-string "("))

    NIL
    #<END-OF-FILE {484EE365}>		; 2nd value is condition object
    >


-Rob

-----
Rob Warnock			<rpw3@rpw3.org>
627 26th Avenue			<URL:http://rpw3.org/>
San Mateo, CA 94403		(650)572-2607