1

Since any exception thrown in netty handler stack will generate an upstream event and eventually invoke exceptionCaught in handler the exceptions will not reach the uncaught-exception-handler. Even rethrowing that exception in exceptionCaught method doesn't help (because netty handles it again). I would like to throw (some or all) unchecked exceptions from exceptionCaught method. Is there any way to do this?

2 Answers 2

3

No there is no way todo this. The only thing you can do about is is to handle the Exception in ExceptionCaught. Why is this a problem for you ?

1
  • 1
    This is problem since my the UncaughtExceptionHandler would not get invoked. Since UncaughtExceptionHandler is common to different layers in my application I don't want to replicate that code in exceptionCaught. I guess I would inject instance of UncaughtExceptionHandler in my netty_handler and invoke method explicitly. Although it will be good if there is any hook in exceptionCaught to propagate exception. Thank you for your input. Jan 11, 2012 at 19:08
0

I have to agree with Norman, I had a similar issue. I created a exceptionCaught() method and in it called my exception handling routine. The problem I encountered was my exception handling routine tried to do cleanup and call other Netty methods but that resulted in Netty getting hung.

My fix was to create a new Thread from inside exceptionCaught() that calls my exception handling routine and simple return from exceptionCaught(). This allow Netty's exception handling to finish and resume normal Netty operation. You need to put a 1 second delay inside your new thread before calling any other Netty functions as well. This will assure netty's exception handling is done before my new thread starts its clean up and calls other netty functions. It seems a bit excessive work but it works and avoids race conditions.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.