Clean up catch blocks

- No need to have nested try blocks because the catch block catches everything and rethrows it
- No need to do instanceof-checks
This commit is contained in:
Trustin Lee 2013-04-04 14:48:30 +09:00
parent c25fd78ca0
commit 015e60b00f
4 changed files with 50 additions and 62 deletions

View File

@ -89,13 +89,10 @@ public abstract class ByteToMessageDecoder
callDecode(ctx, in);
}
decodeLast(ctx, in, out);
} catch (Throwable t) {
if (t instanceof CodecException) {
throw (CodecException) t;
} else {
throw new DecoderException(t);
}
} catch (CodecException e) {
throw e;
} catch (Throwable cause) {
throw new DecoderException(cause);
} finally {
if (out.drainToNextInbound(ctx)) {
ctx.fireInboundBufferUpdated();
@ -131,12 +128,10 @@ public abstract class ByteToMessageDecoder
break;
}
}
} catch (Throwable t) {
if (t instanceof CodecException) {
throw (CodecException) t;
} else {
throw new DecoderException(t);
}
} catch (CodecException e) {
throw e;
} catch (Throwable cause) {
throw new DecoderException(cause);
} finally {
if (out.drainToNextInbound(ctx)) {
decodeWasNull = false;

View File

@ -52,6 +52,10 @@ public abstract class MessageToMessageDecoder<I> extends ChannelInboundMessageHa
OutputMessageBuf out = OutputMessageBuf.get();
try {
decode(ctx, msg, out);
} catch (CodecException e) {
throw e;
} catch (Throwable cause) {
throw new DecoderException(cause);
} finally {
out.drainToNextInbound(ctx);
}

View File

@ -53,11 +53,7 @@ public abstract class MessageToMessageEncoder<I> extends ChannelOutboundMessageH
} catch (CodecException e) {
throw e;
} catch (Throwable cause) {
if (cause instanceof CodecException) {
throw (CodecException) cause;
} else {
throw new EncoderException(cause);
}
} finally {
out.drainToNextOutbound(ctx);
}

View File

@ -375,12 +375,10 @@ public abstract class ReplayingDecoder<S> extends ByteToMessageDecoder {
} catch (Signal replay) {
// Ignore
replay.expect(REPLAY);
} catch (Throwable t) {
if (t instanceof CodecException) {
throw (CodecException) t;
} else {
throw new DecoderException(t);
}
} catch (CodecException e) {
throw e;
} catch (Throwable cause) {
throw new DecoderException(cause);
} finally {
if (out.drainToNextInbound(ctx)) {
ctx.fireInboundBufferUpdated();
@ -397,7 +395,6 @@ public abstract class ReplayingDecoder<S> extends ByteToMessageDecoder {
OutputMessageBuf out = OutputMessageBuf.get();
try {
while (in.isReadable()) {
try {
int oldReaderIndex = checkpoint = in.readerIndex();
int outSize = out.size();
S oldState = state;
@ -434,14 +431,11 @@ public abstract class ReplayingDecoder<S> extends ByteToMessageDecoder {
"if it returned a decoded message (caused by: " +
getClass() + ')');
}
} catch (Throwable t) {
if (t instanceof CodecException) {
throw (CodecException) t;
} else {
throw new DecoderException(t);
}
}
}
} catch (CodecException e) {
throw e;
} catch (Throwable cause) {
throw new DecoderException(cause);
} finally {
if (out.drainToNextInbound(ctx)) {
decodeWasNull = false;
@ -465,5 +459,4 @@ public abstract class ReplayingDecoder<S> extends ByteToMessageDecoder {
super.channelReadSuspended(ctx);
}
}