[racket] Dirt-simple exceptions

From: Robby Findler (robby at eecs.northwestern.edu)
Date: Sun Sep 5 08:42:56 EDT 2010

I think you want with-handlers.

(with-handlers ([exn:fail? (lambda (exn) put-specified-default-here)])
   try-something-here)

Robby

On Sun, Sep 5, 2010 at 7:36 AM, Mark Carter <mcturra2000 at yahoo.co.uk> wrote:
> I can't get my head around Racket's exception mechanism. I want to say "try
> something, and if it fails, return a specified default value".
>
> This returns the expected result:
>   (with-exception-handler (lambda (x) "Oops") (/ 1 0))
> because it returns "Oops". However, if I type
>   (with-exception-handler (lambda (x) "Oops") (/ 6 2))
> then I also get "Oops". It should return 3.
>
> Is there a simple way to accomplish what I'm looking for?
>
>
>
>
> _________________________________________________
>  For list-related administrative tasks:
>  http://lists.racket-lang.org/listinfo/users
>


Posted on the users mailing list.