Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Stack Trace

 
Natraj Gudla
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Is it possible that i can get the stack trace printed though i do not explicitly handle any exceptions in my program.?
 
Anupreet Arora
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just create an exception and use its printStackTrace method, to print the stack trace at the default output.
If you don't throw the Exception object, you don't need to catch or handle it.
For example, at the location where you want the stack trace, just add the following code:

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

I hope this helps!!
Cheeran!
Anupreet
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic