Automatically catch all exceptions thrown by BlazeDS remoting methods?
Is there 开发者_如何学JAVAa 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.
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.
Take a look at Thread.setDefaultUncaughtExceptionHandler, i guess it gives you just what you want.
精彩评论