Ensure that stack-trace is included when exceptions are logged

25 views
Skip to first unread message

Thomas Hallgren

unread,
Apr 2, 2012, 2:06:42 AM4/2/12
to web4j-users
The vomit method created an exception where the stack-trace from the
original exception was lost. This commit changes that by creating a
nested exception instead.

---------------- src/hirondelle/web4j/model/ModelCtorUtil.java
----------------
diff --git a/src/hirondelle/web4j/model/ModelCtorUtil.java b/src/
hirondelle/web4j/model/ModelCtorUtil.java
index bc065e6..efb8e92 100644
--- a/src/hirondelle/web4j/model/ModelCtorUtil.java
+++ b/src/hirondelle/web4j/model/ModelCtorUtil.java
@@ -140,7 +140,7 @@
throw new RuntimeException(
"Cannot reflectively construct Model Object of class "
+ aMOCtor.getDeclaringClass().getName() +
- ", using arguments " + aArgValues + ". Underlying cause: " +
aEx.toString()
+ ", using arguments " + aArgValues + '.', aEx
);
}

John O'Hanley

unread,
Apr 5, 2012, 4:47:16 PM4/5/12
to web4j...@googlegroups.com
Right. I think I'll keep the "Underlying cause.." part. It's redundant, but it doesn't hurt.  Sometimes the underlying cause is waaaaay down on a stack trace.

Thomas Hallgren

unread,
Apr 5, 2012, 5:20:39 PM4/5/12
to web4j...@googlegroups.com
The reason I removed that wording is that when printing stack traces, it's reported with the phrase "Caused by". The
resulting output then become "Caused by: Underlying cause: ".

On 04/05/2012 10:47 PM, John O'Hanley wrote:
> Right. I think I'll keep the "Underlying cause.." part. It's redundant, but it doesn't hurt. Sometimes the underlying
> cause is waaaaay down on a stack trace.

> --
> You received this message because you are subscribed to the Google Groups "web4j-users" group.
> To view this discussion on the web visit https://groups.google.com/d/msg/web4j-users/-/4k0W6Bb-btAJ.
> To post to this group, send email to web4j...@googlegroups.com.
> To unsubscribe from this group, send email to web4j-users...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/web4j-users?hl=en.

John O'Hanley

unread,
Apr 5, 2012, 6:08:26 PM4/5/12
to web4j...@googlegroups.com
Ok. I prefer this style:


    throw new RuntimeException(
      "Cannot reflectively construct Model Object of class "
      + aMOCtor.getDeclaringClass().getName() +
      ", using arguments " + aArgValues + ". " + aEx.toString(),
      aEx
    );

I would like to have the underlying exception message in the top level string too.

Thomas Hallgren

unread,
Apr 6, 2012, 2:22:11 AM4/6/12
to web4j...@googlegroups.com
Yes, that makes a lot of sense.
Reply all
Reply to author
Forward
0 new messages