Meg*_*rog 7 exception-handling netty
(版本:Netty 4.0.4.Final)
如果异常上升ChannelInboundHandler,我可以在exceptionCaught()方法中处理它,但如果异常上升ChannelOutboundHandler,我不能.因为,exceptionCaught()不是电话.为什么会这样?
只有通过分析未来结果来处理出站异常的方法如下:
channel.writeAndFlush(serverPacket).addListener(new ChannelFutureListener() {
@Override
public void operationComplete(ChannelFuture future) throws Exception {
if (!future.isSuccess()) {
future.cause().printStackTrace();
}
}
});
Run Code Online (Sandbox Code Playgroud)
但这非常不方便.
Nor*_*rer 11
这是设计......出站操作只通过Future通知,否则我们需要做双重通知,这会产生一些性能损失.如果您想将它传播到exceptionCaught处理程序,您只需将ChannelFutureListener.FIRE_EXCEPTION_ON_FAILURE添加为返回的ChannelFuture的Listener.