[jboss-jira] [JBoss JIRA] (LOGTOOL-101) Exception transformation
James Perkins (JIRA)
issues at jboss.org
Fri Apr 1 12:01:00 EDT 2016
[ https://issues.jboss.org/browse/LOGTOOL-101?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13185484#comment-13185484 ]
James Perkins commented on LOGTOOL-101:
---------------------------------------
Do you want the stack trace just appended to the created exceptions stack trace? So something like:
{code:java}
final StackTraceElement[] resultStackTrace = result.getStackTrace();
final StackTraceElement[] causeStackTrace = cause.getStackTrace();
final int newLen = resultStackTrace.length + causeStackTrace.length;
final StackTraceElement[] newStackTrace = Arrays.copyOf(resultStackTrace, newLen);
System.arraycopy(causeStackTrace, 0, newStackTrace, resultStackTrace.length, causeStackTrace.length);
result.setStackTrace(newStackTrace);
{code}
WRT cloning I'm not sure I get what you mean.
Note I'll also fix the {{@Pos}} documentation as it's rather poor :)
> Exception transformation
> ------------------------
>
> Key: LOGTOOL-101
> URL: https://issues.jboss.org/browse/LOGTOOL-101
> Project: Log Tool
> Issue Type: Feature Request
> Reporter: David Lloyd
> Assignee: James Perkins
>
> 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:
> {code}
> @Message(id = 1234, "Binding to %s failed")
> IOException bindFailed(SocketAddress bindAddress, @TransformException IOException cause)
> {code}
> 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:
> {code}
> @Message(id = 1234, "Binding to %s failed: %s")
> IOException bindFailed(SocketAddress bindAddress, IOException cause)
> {code}
> An alternative approach is to add an annotation for copying the stack trace:
> {code}
> @Message(id = 1234, "Binding to %s failed")
> IOException bindFailed(SocketAddress bindAddress, @CopyStackFrom IOException cause)
> {code}
> Note that in this case the original exception message is lost. The next variant would preserve the message:
> {code}
> @Message(id = 1234, "Binding to %s failed: %s")
> IOException bindFailed(SocketAddress bindAddress, IOException cause, @CopyStackFrom IOException cause2)
> {code}
> And now to eliminate the duplication:
> {code}
> @Message(id = 1234, "Binding to %s failed: %s")
> IOException bindFailed(SocketAddress bindAddress, @CopyStackFrom @Pos(2) IOException cause)
> {code}
> Note that I don't recall if @Pos is 1- or 0-based, so I guessed.
--
This message was sent by Atlassian JIRA
(v6.4.11#64026)
More information about the jboss-jira
mailing list