Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Debug tool

 
Edward Chen
Ranch Hand
Posts: 798
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Debug tool

When java has some error, we could use "e.printstack()" to see the error message, and we could how the application goes step by step , one class by class, function by function. That is very helpful.

But the problem, these info will be there just when java has error exception. My question, when we run a non-exception application, how could I see those message, step by step , one class by class, function by function ?

Any suggestion ?

Thanks
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24211
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's called a "debugger", and Integrated Development Environments (IDEs) like Eclipse (www.eclipse.org), NetBeans (java.sun.com), IntelliJ IDEA (www.jetbrains.com) and JBuilder have nice graphical ones. There's even a simple command-line debugger, "jdb", that comes with the JDK.
 
Edward Chen
Ranch Hand
Posts: 798
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am doing a Struts application in Tomcat 5.0. Which tool is for this ?

Thanks
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Learning your debugger is a good thing, but ...

You're probably accustomed to seeing stack traces only when you catch an exception. But you can create an exception and print the trace (without throwing or catching it) any time:

new Exception("debugging only").printStackTrace();

This is absolutely not something you'd want to leave in production code because creating the exception is rather expensive and printing messes up your log. I did this once when we had no idea how a particular cache was getting cleared at very infrequent intervals but took it out as soon as the mystery was solved.
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24211
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Edward Chen:
I am doing a Struts application in Tomcat 5.0. Which tool is for this ?

Thanks


I think most of these can actually debug code running in Tomcat. Certainly IDEA and Eclipse can (with the proper plug-ins.)
 
Joel McNary
Bartender
Posts: 1840
Eclipse IDE Java Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Stan James:

new Exception("debugging only").printStackTrace();


Why not simply Thread.dumpStack()? Not that I think Thread.dumpStack() is any more efficient; it does the same thing, methinks....
 
Edward Chen
Ranch Hand
Posts: 798
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thread.dumpStack()

is what I am looking for. I appreciate all your guys responses.
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks, Joel. I didn't know that one. The API is just too darned big!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic