Is there a way to automatically catch all (unchecked) exceptions thrown by BlazeDS remoting methods, without wrapping each one in a last-resort try/catch block? My code catches any checked exceptions as required, but I'd prefer that stray NullPointerExceptions, ArrayIndexOutOfBoundsExceptions and the like don't end up being set to the client.
+1
A:
Take a look at Thread.setDefaultUncaughtExceptionHandler, i guess it gives you just what you want.
davyM
2010-07-07 14:04:30
Thanks, I didn't know about that, but I don't think it will work in my situation. All exceptions uncaught in my code will be caught by BlazeDS and won't make it up to that default handler. I'd like a way to catch them before Blaze gets them, or perhaps some sort of filter if BlazeDS supported it.
fizban
2010-07-07 17:18:03
You might look what you can accomplish with Aspect oriented programming. (AspectJ for example). It is very powerfull, and let you do many things compile time or runtime.
davyM
2010-07-07 20:54:45
+1
A:
I would suggest to use Spring-BlazeDs integration project. One of the benefits is the ExceptionTranslator mechanism which can solve your problem, I wrote an article here.
If you cannot use Spring you can take a look in BlazeDS source code and add your own interceptor. The BlazeDS code is clean and not hard to understand.
Cornel Creanga
2010-07-08 08:42:04
Thanks! Unfortunately our project is not using Spring, but I will do some more poking around in the BlazeDS source and see what I can find.
fizban
2010-07-08 12:02:19