[plt-scheme] Error Checking

From: Carl Eastlund (carl.eastlund at gmail.com)
Date: Thu Jun 18 16:56:19 EDT 2009

On Thu, Jun 18, 2009 at 4:49 PM, Jakub Piotr Cłapa<jpc-ml at zenburn.net> wrote:
> On 6/18/09 7:43 PM, Paulo J. Matos wrote:
>>
>> I have tried to look at the
>> definition of raise-user-error in the plt source code but couldn't
>> find anything. Can someone point me to it or correct my design if I
>> could do something simpler?
>
> The raise functions are actually very simple. This is how I do it:
>
> (define-struct (exn:fail:syntax exn:fail) ())
>
> (define (raise-syntax-error msg)
>  (raise (make-exn:fail:syntax msg (current-continuation-marks))))
>
> You would probably like to do something more interesing with msg.

Note that exn:fail:syntax and raise-syntax-error already have
definitions in PLT Scheme.  But if I were to provide my own definition
for a raise-* function, I would allow printf-style messages like this:

(define (raise-syntax-error fmt . args)
  (raise (make-exn:fail:syntax (apply format fmt args)
(current-continuation marks))))

--Carl


Posted on the users mailing list.