Commit 5996305f authored by zengtianlai3's avatar zengtianlai3

2.3.9 异常处理:泛化的捕获异常

parent 4fff1fb2
......@@ -26,22 +26,22 @@ public class TcpClient {
Thread thread = new Thread(new Runnable() {
@Override
public void run() {
try {
EventLoopGroup eventLoopGroup = new NioEventLoopGroup();
Bootstrap bootstrap = new Bootstrap();
try {
bootstrap
.channel(NioSocketChannel.class)
.option(ChannelOption.SO_KEEPALIVE, true)
.group(eventLoopGroup)
.remoteAddress(host, port)
.handler(channelInitializer);
ChannelFuture future = bootstrap.connect(host, port);
future.addListener(connectionListener);
} catch (Exception e) {
// TODO Auto-generated catch block
log.error("Tcp客户端异常,端口:{}",port);
} catch (NullPointerException e) {
log.error(e.getMessage());
}catch (IllegalStateException ex) {
log.error(ex.getMessage());
}
ChannelFuture future = bootstrap.connect(host, port);
future.addListener(connectionListener);
}
});
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment