actually I think this will not work in netty 4.1 due our java version requirement and so you need to handle this kind of stuff differently. The rethrowing Throwable? Then we can use `PlatformDependent.throwException` instead. Yep... Only works on java8+
ReferenceCountUtil.release(cast) could shade the exception of encode at function write of MessageToMessageEncoder
### Expected behavior
![image](https://user-images.githubusercontent.com/10280338/174937458-9bceea3c-4099-43e7-81c0-0022969f29dc.png)
Function `encode` at line 89 is declared to throw exceptions, and then if `ReferenceCountUtil.release(cast)` at line 91 throws an exception too, the exception threw by `encode` will be shown before the exception threw by `ReferenceCountUtil.release(cast)`.

### Actual behavior
The excpetion threw by `encode` will be shaded by the exception threw by `ReferenceCountUtil.release(cast)`.
### Steps to reproduce

### Minimal yet complete reproducer code (or URL to code)

### Netty version
on branch 4.1
### JVM version (e.g. `java -version`)
openjdk version "1.8.0_201"
### OS version (e.g. `uname -a`)

codec/src/main/java/io/netty/handler/codec/MessageToMessageEncoder.java
codec/src/main/java/io/netty/handler/codec/MessageToMessageEncoder.java
diff --git a/codec/src/main/java/io/netty/handler/codec/MessageToMessageEncoder.java b/codec/src/main/java/io/netty/handler/codec/MessageToMessageEncoder.java
index eb29eb87fca..4973c9bb0b7 100644
--- a/codec/src/main/java/io/netty/handler/codec/MessageToMessageEncoder.java
+++ b/codec/src/main/java/io/netty/handler/codec/MessageToMessageEncoder.java
@@ -23,6 +23,7 @@
 import io.netty.util.ReferenceCountUtil;
 import io.netty.util.ReferenceCounted;
 import io.netty.util.concurrent.PromiseCombiner;
+import io.netty.util.internal.PlatformDependent;
 import io.netty.util.internal.StringUtil;
 import io.netty.util.internal.TypeParameterMatcher;
 
@@ -87,9 +88,11 @@ public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise)
                 I cast = (I) msg;
                 try {
                     encode(ctx, cast, out);
-                } finally {
-                    ReferenceCountUtil.release(cast);
+                } catch (Throwable th) {
+                    ReferenceCountUtil.safeRelease(cast);
+                    PlatformDependent.throwException(th);
                 }
+                ReferenceCountUtil.release(cast);
 
                 if (out.isEmpty()) {
                     throw new EncoderException(
