In the majority of my Coldbox apps, I have a BaseHandler Around Advice aroundHandler()
that wraps all events. This gives me a convenient way to catch specific exception types, like BadRequest
, NotFound
, EntityNotFound
, ValidationException
, etc…
However, I discovered something today, that I’m not sure is by design, or a bug. If I use a handler Pre Advice, and throw an exception that would normally be caught by the aroundHandler()
it does not, and goes straight to Whoops.
So my question is this, can aroundHandler()
be used to catch an exception that is thrown in a Pre Advice? Or do Pre Advices get called independently and outside of any Around Advices?
From the docs:
Blockquote
This will allow you to run both before and after advices but also surround the method call with whatever logic you want liketransactions
,try/catch
blocks,locks
or even decide to not execute the action at all
Here’s an sample aroundHandler I like to use:
https://gist.github.com /homestar9/15de3fb4dc8f5fa076813f534b1c3ea9
Here’s a sample Pre Advice method:
https://gist.github.com /homestar9/902add3d2043ccd5d87e5342c0537cbf
Note: The form wouldn’t let me post these code samples for some reason (403 errors) so you’ll need to fix the links yourself.