On 3/23/19, David Storrs <david.sto...@gmail.com> wrote:
> Alex makes good points, but I'm curious about the original question:  Is
> there a straightforward way to tell which function it was whose contract
> was violated, aside from parsing the message?  Or, more generally, where a
> specific exception came from?

For blame errors, it might help to grab the blame object and ask it
some questions.

```
  #lang racket

  (module a racket
    (provide (contract-out (f (-> symbol? symbol?))))
    (define (f sym)
      (symbol->string sym)))
  (require 'a)

  (with-handlers ((exn:fail:contract:blame?
                    (lambda (blame-err)
                      (define b (exn:fail:contract:blame-object blame-err))
                      (printf "bad value = ~s~n" (blame-value b)))))
    (f 'X))
  ;; bad value = f
```

Docs:
https://docs.racket-lang.org/reference/Building_New_Contract_Combinators.html#(part._.Blame_.Objects)

-- 
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