Details
-
Feature Request
-
Resolution: Done
-
Major
-
None
-
None
Description
I'd like to be able to transform an exception message. What this means is, create a new exception, embed its message in my message, and copy its stack trace to mine.
Something like this:
@Message(id = 1234, "Binding to %s failed")
IOException bindFailed(SocketAddress bindAddress, @TransformException IOException cause)
This would yield a message like: "Binding to 1.2.3.4/1234 failed: Address already in use". Note the addition of the ": " and the source string.
Note that I can almost do this now, except that there's no way to copy the exception stack:
@Message(id = 1234, "Binding to %s failed: %s")
IOException bindFailed(SocketAddress bindAddress, IOException cause)
An alternative approach is to add an annotation for copying the stack trace:
@Message(id = 1234, "Binding to %s failed")
IOException bindFailed(SocketAddress bindAddress, @CopyStackFrom IOException cause)
Note that in this case the original exception message is lost. The next variant would preserve the message:
@Message(id = 1234, "Binding to %s failed: %s")
IOException bindFailed(SocketAddress bindAddress, IOException cause, @CopyStackFrom IOException cause2)
And now to eliminate the duplication:
@Message(id = 1234, "Binding to %s failed: %s")
IOException bindFailed(SocketAddress bindAddress, @CopyStackFrom @Pos(2) IOException cause)
Note that I don't recall if @Pos is 1- or 0-based, so I guessed.