Racket hash-table default failure result unhelpful

Viewed 467

In Racket, if you try to hash-ref for a key the hash does not contain, e.g.

(define a-hash #hash((1 . "a")
                     (2 . "b")))
(hash-ref a-hash 3)

An exn:fail:contract is raised.

...\Racket\collects\racket\private\more-scheme.rkt:263:2: hash-ref: no value found for key

Unfortunately, exn:fail:contract is unhelpfully broad. It's the same type of exception you get if you try to apply a value as a procedure

(with-handlers ((exn:fail? print))
  (10 11))

(exn:fail:contract "application: not a procedure;\n expected a procedure that can be applied to arguments\n given: 10\n arguments...:\n 11" #)

Is there any way to change the default value of hash-ref's failure-result from outside the code using it? Could I go into my Racket installation and change it there? That seems Bad and Dangerous. What are my options? I could parse the exception message, but that reeks of hacky and error-prone.

1 Answers
Related