What happens when we say e.printStackTrace();? Here e is any Exception. Does it stop the normal execution and actually remove the activation records from the thread stack to give the stack trace of the exception? Is it a good idea to use it in applications?
What happens when we say e.printStackTrace(); ? Here e is any Exception . Does
Share
No.
No.
The information has already been captured. This happens in the constructors for
Throwable; i.e. when younewan exception, not when youthrowit. TheThrowableconstructor calls thefillInStackTrace()native method which takes a snapshot of the stack and stores the resultingStackTraceElement[]in a private variable that is used later when printing the stack trace.(For the record, this is specified in the javadoc for the constructors of
Throwable.Well it is rather expensive and can produce a lot of output. But if you need the stack trace for diagnostic purposes … do it.