Commit 5996305f authored by zengtianlai3's avatar zengtianlai3

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

parent 4fff1fb2
...@@ -26,22 +26,22 @@ public class TcpClient { ...@@ -26,22 +26,22 @@ public class TcpClient {
Thread thread = new Thread(new Runnable() { Thread thread = new Thread(new Runnable() {
@Override @Override
public void run() { public void run() {
try {
EventLoopGroup eventLoopGroup = new NioEventLoopGroup(); EventLoopGroup eventLoopGroup = new NioEventLoopGroup();
Bootstrap bootstrap = new Bootstrap(); Bootstrap bootstrap = new Bootstrap();
try {
bootstrap bootstrap
.channel(NioSocketChannel.class) .channel(NioSocketChannel.class)
.option(ChannelOption.SO_KEEPALIVE, true) .option(ChannelOption.SO_KEEPALIVE, true)
.group(eventLoopGroup) .group(eventLoopGroup)
.remoteAddress(host, port) .remoteAddress(host, port)
.handler(channelInitializer); .handler(channelInitializer);
ChannelFuture future = bootstrap.connect(host, port); } catch (NullPointerException e) {
future.addListener(connectionListener); log.error(e.getMessage());
}catch (IllegalStateException ex) {
} catch (Exception e) { log.error(ex.getMessage());
// TODO Auto-generated catch block
log.error("Tcp客户端异常,端口:{}",port);
} }
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