[plt-scheme] restart exception handling?

From: David Vanderson (david.vanderson at gmail.com)
Date: Sun Jul 13 15:22:23 EDT 2008

Matthew Flatt wrote:
> Exceptions are typically raised (both in the core and in Scheme code)
> with code like this:
>   (define (mega-fun x y z)
>     (unless (integer? x)
>       (raise-type-error 'mega-fun "integer" x))
>     (unless (list? y)
>       (raise-type-error 'mega-fun "list" y))
>     (for-each (lambda (e)
>                 (when (equal? e x)
>                   (error 'mega-fun "cannot include val in list: ~e" x)))
>                y)
>      ...)
> To make those exceptions continuable, the function has to be written in
> a different way, and often that's a pain:
>   (define (mega-fun x y z)
>     (if (not (integer? x))
>        (raise-continuable-type-error 'mega-fun "integer" x))
>        (if (not (list? y))
>            (raise-continuable-type-error 'mega-fun "list" y))
>            ((let/ec esc
>               (for-each (lambda (e)
>                           (when (equal? e x)
>                             (esc
>                              (lambda ()
>                                (continuable-error 
>                                 'mega-fun 
> 			        "cannot include val in list: ~e"
>                                 x)))))
>                         y)
>                (lambda () ...))))

Thanks very much for the explanations.

Is there a reason why each exception should be thrown in tail position 
with respect to the function?  Is that the convention for continuable 

Could you please elaborate on why you couldn't (or shouldn't) just 
replace "raise-type-error" with "raise-continuable-type-error"?


Posted on the users mailing list.