As Ben pointed out, if the exception is a `real exn:fail:contract:blame`,
you don't even need to parse the message string:

#lang racket

(define/contract (wants-exact x)
  (-> exact? exact?)
  x)

(define/contract (wants-inexact x)
  (-> inexact? inexact?)
  x)

(define (show-which-was-violated x)
  (with-handlers ([exn:fail:contract:blame?
                   (λ (e)
                     (blame-value
                      (exn:fail:contract:blame-object e)))])
    (wants-exact x)
    (wants-inexact x)))

(map show-which-was-violated '(1 1.0)) ;; '(wants-inexact wants-exact)

-Philip


On Mon, Mar 25, 2019 at 1:11 PM James Platt <j...@biomantica.com> wrote:

>
> On Mar 25, 2019, at 12:49 PM, Matthias Felleisen wrote:
>
> > See how precise the exn message is: 2nd arg of 1st arg of f ~~ not a
> boolean?
>
> Okay.  So the exn message is generated in a systematic way which I can
> count on.  I didn't realize that.  Thanks.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to racket-users+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to