Daniel John Debrunner wrote:
> Oyvind.Bakksjo@Sun.COM wrote:
>>The stack trace isn't created when the Exception object is constructed,
>>it's created when it's thrown. If you throw the same exception object
>>from multiple threads, they will interfer with each other in
>>unpredictable ways.
>
>
>
> That's not what I see in jdk 1.4.2, from IBM & Sun and jdk 1.5. Here's a
> simple program that creates an exception in the method b() but throws it
> in a(). I always see b() in the stack trace.
>
> java.lang.Exception: from b
> at te.b(te.java:20)
> at te.a(te.java:15)
> at te.main(te.java:6)
>
> I've always seen exceptions have the stack trace of where they were
> created. That's also what the jdk 142 javadocs say for Throwable:
>
> 'A throwable contains a snapshot of the execution stack of its thread at
> the time it was created'
OK, red herring from me. :-/ My memory must be playing games with me - I
have used the "create exception" trick earlier to get the current stack
trace, and seemed to recall that I had to actually throw-catch it to get
the stack trace. But that can't be the case then.
--
Oyvind Bakksjo
Sun Microsystems, Database Technology Group
Trondheim, Norway
http://weblogs.java.net/blog/bakksjo/
|