code: public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent e) throws Exception {
          Throwable cause = e.getCause();
  
          // do not print exception if it is BindException.
          // we are trying to search available port below 1024. It is not good to
          // print a flood
          // of error logs during the searching.
          if (cause instanceof java.net.BindException) {
              return;
          }
  
          LOG.error("Exception on connection to " + getRemoteAddress(), e.getCause());
  
          // close the channel unless we are connecting and it is
          // NotYetConnectedException
          if (!((cause instanceof NotYetConnectedException)
                  && _connection.getConnectionState().equals(Connection.State.CONNECTING))) {
              ctx.getChannel().close();
          }
      }
docs: /*
  (non-Javadoc)
  
  @see
  org.jboss.netty.channel.SimpleChannelHandler#exceptionCaught(org.jboss.
  netty.channel.ChannelHandlerContext,
  org.jboss.netty.channel.ExceptionEvent)