[plt-scheme] handle exception

From: Petros Pissias (p.pissias at di.uoa.gr)
Date: Sat May 22 06:57:58 EDT 2004

Hi,

I'm trying to make a programm that draws a function.
The only problem is that sometimes the function 
throws a 'divide by zero exception' that must be handled correctly.

The user is prompted to give the function  [example:  (lambda (x) (/ 1
x))]

I don't want the user to give the exception handling details in the
function
[example: (lambda (x)
    (with-handlers ([exn:application:divide-by-zero? 
                     (lambda (exn) +inf.0)])
      (/ 1 x)))  ]

I'm trying to 'insert' the exception handling code after the "
(define func (read))" which reads the function,
but I can't get it right...

I've tried things like :

(define quoted_func (read))

 (define full_func (list (first quoted_func) (first (rest quoted_func))
(with-handlers ([exn:application:divide-by-zero? 
                     (lambda (exn) +inf.0)]) (first (rest (rest
quoted_func))) ) ) )

and variations but with no luck... 

Is there a better way to try and handle the exception ?

Thanks in Advance

Petros Pissias





Posted on the users mailing list.