How to display the stacktrace?

A

Aaron Fude

Hi,

Very often, for debugging purposes in Swing applications, I like to
see the stacktrace so I do the following:

try {
throw new RuntimeException();
}
catch (Exception e) {
e.printStackTrace();
}

Is there a more tasteful way of accomplishing this?

Thanks!
 
M

Mark Space

Aaron said:
Hi,

Very often, for debugging purposes in Swing applications, I like to
see the stacktrace so I do the following:

try {
throw new RuntimeException();
}
catch (Exception e) {
e.printStackTrace();
}

I think just this will work:

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

or even

new Excpetion().printStackTrace();

No need to throw it first.
 
A

Aaron Fude

I think just this will work:

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

or even

   new Excpetion().printStackTrace();

No need to throw it first.

Cool beans!
 
L

Logan Shaw

Aaron said:
Very often, for debugging purposes in Swing applications, I like to
see the stacktrace so I do the following:

try {
throw new RuntimeException();
}
catch (Exception e) {
e.printStackTrace();
}

Is there a more tasteful way of accomplishing this?

How about Thread.dumpStack()?

Or if you want control over where it goes, then you can get
an array from Thread.currentThread().getStackTrace() and
print each element of that, or make it available in your GUI
somewhere if that's appropriate/convenient.

- Logan
 
F

Francois

Aaron Fude said:
Very often, for debugging purposes in Swing applications, I like to
see the stacktrace so I do the following:

You can also do it manually with StackTraceElement :

catch(Exception e)
{
StackTraceElement[] s=e.getStackTrace();
int n;
for (n=0; n<s.length; n++)
{
g.drawString(s[n].toString(), 0, n*20);
}
}

Francois
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top