Commit 5996305f authored by zengtianlai3's avatar zengtianlai3

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

parent 4fff1fb2
...@@ -26,23 +26,23 @@ public class TcpClient { ...@@ -26,23 +26,23 @@ 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);
} catch (NullPointerException e) {
log.error(e.getMessage());
}catch (IllegalStateException ex) {
log.error(ex.getMessage());
}
ChannelFuture future = bootstrap.connect(host, port); ChannelFuture future = bootstrap.connect(host, port);
future.addListener(connectionListener); future.addListener(connectionListener);
} catch (Exception e) {
// TODO Auto-generated catch block
log.error("Tcp客户端异常,端口:{}",port);
}
} }
}); });
thread.start(); thread.start();
......
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