problem catching exceptions

26 views
Skip to first unread message

Wei Hsu

unread,
Feb 27, 2014, 5:36:37 AM2/27/14
to comp...@googlegroups.com
Hello, I'm trying to implement an exception handler and am having trouble getting it to work. Can spot what I'm doing wrong?


Thanks, Wei

James Reeves

unread,
Feb 27, 2014, 8:49:12 AM2/27/14
to Compojure
A failed assert raises an AssertionError, which does not inherit from the Exception class.

In Java, Throwable is the base error class, and subclassing this are Errors and Exceptions. Errors are for serious problems that the application should not attempt to catch, whereas Exceptions are things your application might want to catch.

An assertion error is an Error, rather than an Exception, because it indicates your application is in an unexpected state.

- James


--
You received this message because you are subscribed to the Google Groups "Compojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email to compojure+...@googlegroups.com.
To post to this group, send email to comp...@googlegroups.com.
Visit this group at http://groups.google.com/group/compojure.
For more options, visit https://groups.google.com/groups/opt_out.

Wei Hsu

unread,
Feb 28, 2014, 11:03:48 PM2/28/14
to comp...@googlegroups.com, ja...@booleanknot.com
Thanks, that's spot on. The assertion did alert me to a bug in the application. However, I feel like even unexpected assertion errors should not be exposed to the user in the request body. Would it be good practice to also catch Errors in the wrapper?

James Reeves

unread,
Mar 1, 2014, 8:01:42 AM3/1/14
to Wei Hsu, Compojure
Yes, the one time to might want to catch any Throwable is for logging purposes, or to hide the stacktrace from users.

Sorry if I wasn't clear on that.

- James
Reply all
Reply to author
Forward
0 new messages