Thanks to the ever helpful Matthew Flatt, I can now catch scheme errors before they cause an exception and stop everything running. It’s also possible to detect that an error has occurred and do something else (play a suitable sample, electrify the keyboard…)

(define error-happened #f)

(define (my-error-handler n)
    (set! error-happened #t))

 (with-handlers ([(lambda (x) #t) my-error-handler])
    (modulo 0 1 2)) ; some erroneous code

(when (error-happened)

Leave a Reply

Your email address will not be published. Required fields are marked *