How to handle exception in decoders/handlers?
"이희승 (Trustin Lee)"
trustin at gmail.com
Fri Jun 19 14:06:28 EDT 2009
Hi,
It seems like one of the handlers in your pipeline closes the connection
on an exceptionCaught event (perhaps the last handler.) I would catch
the exception in the last handler and send the error message there
rather than sending it in the decoder, because it's often a good idea to
separate protocol state from codec.
HTH,
Trustin
On 2009-06-20 오전 2:42, infectedrhythms wrote:
>
> Hi, I have implemented a simple decoder and it works fine.
>
> Now if there is an error I want to throw an exception catch and reply back
> to the client, kind of like an HTTP 500 error.
>
> So if the decoder fails it should write back to the client the error that
> occurred.
>
> @Override
> protected Object decode(ChannelHandlerContext ctx, Channel channel,
> ChannelBuffer buf) throws Exception {
>
> ... do stuff here...
>
> throw new Exception("Errrorrrr!");
> }
>
> @Override
> public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent e)
> throws Exception {
>
> super.exceptionCaught(ctx, e);
>
> e.getChannel().write("Damn it Jim!"); <-- Throws a ClosedChannelException
>
> }
--
— Trustin Lee, http://gleamynode.net/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 258 bytes
Desc: OpenPGP digital signature
Url : http://lists.jboss.org/pipermail/netty-users/attachments/20090620/28c91c7f/attachment.bin
More information about the netty-users
mailing list