Exception Handling in the provided Channel Handlers

Trustin Lee tlee at redhat.com
Wed Mar 25 14:53:28 EDT 2009


2009/3/24 Utkarsh Srivastava <utkarsh at gmail.com>:
> Hi,
>
> I want to use some of the provided channel handlers, e.g.,
> LengthFieldBasedFrameDecoder. However, my question is what happens if the
> client sends a malformed packet, e.g, one that has a huge length encoded in
> the first 4 bytes. Currently, the handler throws an exception which will
> probably cause the connection to be closed on the client.
>
> I would instead want to send a nice error message back to client. How can I
> do that?

An exceptionCaught event does not always closes a connection.  A
connection is closed automatically only when an IOException is raised.
 You can decide what to do in your handler's exceptionCaught() method.
 For example, you could send an error response depending on the type
of the caught exception.

If this doesn't work, please let me know.

HTH,

— Trustin Lee, http://gleamynode.net/




More information about the netty-users mailing list