#lang racket ; pattern for ; TRY ; CATCH ; RESUME (define testit (lambda (x y default) ; RESUME (call/cc (lambda (RESUME) ; when everything is finished we invoke RESUME (let ( (exception ; the context around this is the catch, it expects an exception result (call/cc (lambda (THROW) ; TRY ; here is the body of the try, which computes result (let ((result ; compute the result in here, or throw (if (not (eq? 0 y)) (/ x y) (THROW "DivBy0")) )) ; it worked, so return result (RESUME result) ) ) ) ) ) ; CATCH ; what happens here is the catch, invoked only if we throw ; in this case we return the default value (display "Caught ")(display exception)(newline) (RESUME default) ) ) ))) (testit 4 2 "Arrgh, do not divide by 0") (testit 4 0 "Arrgh, do not divide by 0")