Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Java (http://www.velocityreviews.com/forums/f30-java.html)
-   -   How to display the stacktrace? (http://www.velocityreviews.com/forums/t603486-how-to-display-the-stacktrace.html)

Aaron Fude 04-02-2008 02:38 AM

How to display the stacktrace?
 
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!

Mark Space 04-02-2008 02:44 AM

Re: How to display the stacktrace?
 
Aaron Fude wrote:
> 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.

Aaron Fude 04-02-2008 03:04 AM

Re: How to display the stacktrace?
 
On Apr 1, 10:44*pm, Mark Space <marksp...@sbc.global.net> wrote:
> Aaron Fude wrote:
> > 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.


Cool beans!


Logan Shaw 04-02-2008 05:21 AM

Re: How to display the stacktrace?
 
Aaron Fude wrote:
> 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

Francois 04-02-2008 07:14 AM

Re: How to display the stacktrace?
 
"Aaron Fude" <aaronfude@gmail.com> a écrit dans le message de news:
6d2017b2-26f6-4bf6-8de7-b49c3283e0f9...oglegroups.com...
> 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



Roedy Green 04-02-2008 03:59 PM

Re: How to display the stacktrace?
 
On Tue, 1 Apr 2008 19:38:34 -0700 (PDT), Aaron Fude
<aaronfude@gmail.com> wrote, quoted or indirectly quoted someone who
said :

>Is there a more tasteful way of accomplishing this?


What is distasteful about your existing code. If you want some
alternatives see http://mindprod.com/jgloss/trace.html
--

Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com


All times are GMT. The time now is 07:17 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.