views:

44

answers:

1

Hi all,

I am migrating my Seam 2 powered application to CDI and one of the things that is critical for me to retain is the error handling. In Seam 2, I simply replaced the default exception handler with my own, but in CDI, I am guessing I'll have to use an Interceptor.

How would I set this up as using an Interceptor requires me to specify where it will intercept calls? I mostly want to accomplish auditing, so when an exception occurs, it is logged, then a notification (email, xmpp, sms, phone call) is sent out to administrators.

When an exception occurs, is there simply an event that I can listen for and act on?

Walter

A: 

Are you using JSF2? If yes, instead of writing an Interceptor, you could register an ExceptionHandlerFactory in your web.xml as described here. In a CustomExceptionHandler, you can catch all Exceptions and handle them programmatically. I'm using this approach in my JEE6-CDI-app, find it quite okay.

ifischer
That looks like a good candidate. I also want to catch exceptions fro m asynchronous jobs in a central place. Perhaps I will have 1 for each, one for JSF and one for asynchronous jobs.
Multiple ExceptionHandlerFactories? Didn't try that. Maybe you could let me know if it works. One additional hint: if you unwrap the exception in the ExceptionHandlerFactory (its wrapped in FacesException, sometimes also EvaluationException) to its original type and throw it from inside the factory, you can handle the exceptions declaratively in the web.xml (but then you have to do some tricks do transmit informations about the exception to a jsf page).
ifischer