maxim_jaffe
2020-9-6 12:10:06

I only started getting recursion for real with Little Schemer. Great book.


ahmadrasyidsalim
2020-9-6 17:32:38

@ahmadrasyidsalim has joined the channel


robbiehk131
2020-9-6 17:41:10

@robbiehk131 has joined the channel


robbiehk131
2020-9-6 17:47:03

Does anybody know how to get the message of an error? I want to do something like: (check-equal? (function-being-run).errormessage() "expected error message") And I know in C++, we can do: try { something } catch (exn) { return exn.what()} Is there a Racket equivalent?


laurent.orseau
2020-9-6 17:54:06

You can use check-exn to check for exception types (https://docs.racket-lang.org/rackunit/api.html?q=check-exn#%28def._%28%28lib._rackunit%2Fmain..rkt%29._check-exn%29%29) but if you really want to check the exception message itself you can use : (check-equal? (with-handlers ([exn? (λ (e) (exn-message e))]) ...) "the expected error message")


laurent.orseau
2020-9-6 17:55:02

with-handlers is the catcher basically


sorawee
2020-9-6 18:11:47

check-exn also accepts a regexp argument, so there’s no need for with-handlers.


laurent.orseau
2020-9-6 18:15:20

Ha, first time I notice that! :slightly_smiling_face:


laurent.orseau
2020-9-6 18:16:35

(although I never feel comfortable checking the message itself)


robbiehk131
2020-9-6 18:32:02

Thanks guys! check-exn solved the problem!