Computing.Net > Forums > Programming > java printStackTrace()

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

java printStackTrace()

Reply to Message Icon

Name: jerryhz
Date: February 18, 2009 at 14:52:26 Pacific
OS: Windows 2000
CPU/Ram: 2G
Subcategory: Java
Comment:

In java, we can call printStackTrace() method from exception object, such as:

Exception ex = new Exception();
ex.printStackTrace();

I remembered I used to call printStackTrace() from system.out.... I cannot remmber now. How can I print call hirerachy if I don't use exception object?

Thanks!



Sponsored Link
Ads by Google

Response Number 1
Name: klint
Date: February 19, 2009 at 07:38:40 Pacific
Reply:

I can't think of any way of doing it without using an Exception object (or at least a Throwable, from which Exception is derived) but here's one way to print a stack trace:

    for (StackTraceElement e : new Throwable().getStackTrace())
        System.out.println(e);


0

Response Number 2
Name: jerryhz
Date: February 19, 2009 at 09:06:35 Pacific
Reply:

Thanks for your reply. I have recalled another way of doing this:

Thread.dumpStack();


0

Response Number 3
Name: klint
Date: February 19, 2009 at 09:18:01 Pacific
Reply:

Thanks for sharing, that's much better.


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More


Need Help Batch edit textfile keep ...



Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: java printStackTrace()

Java I/O Help www.computing.net/answers/programming/java-io-help/12986.html

cpu schedualing in java www.computing.net/answers/programming/cpu-schedualing-in-java/14341.html

Object Serialization in Java www.computing.net/answers/programming/object-serialization-in-java/10261.html