import io . netty . channel .*; import java . net . SocketAddress ; public class ExceptionHandler extends ChannelDuplexHandler { @Override public void exceptionCaught ( ChannelHandlerContext ctx , Throwable cause ) { // Uncaught exceptions from inbound handlers will propagate up to this handler } @Override public void connect ( ChannelHandlerContext ctx , SocketAddress remoteAddress , SocketAddress localAddress , ChannelPromise promise ) { ctx . connect ( remoteAddress , localAddress , promise . addListener ( new ChannelFutureListener () { @Override public void operationComplete ( ChannelFuture future ) { if (! future . isSuccess ()) { // Handle connect exception here... } } })); } @Override public void write ( ChannelHandlerContext ctx , Object msg , ChannelPromise promise ) { ...