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 ?
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.
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.
A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
author and iconoclast