This is probably a newbie question, but hope you can help me. :) I have something like this:
try { //try to do something there } catch (IOException e) { //handle the exception e.printStackTrace(); }
I am using NetBeans IDE and for some reason the printStackTrace is underlined in a squiggly line. When I press Alt+Enter, it says Throwable.printStackTrace() should be removed. What does this mean? Could anyone give more insight as what this may mean? Or can I ignore this?
Thanks!
e. printStackTrace() is generally discouraged because it just prints out the stack trace to standard error. Because of this you can't really control where this output goes. The better thing to do is to use a logging framework (logback, slf4j, java.
printStackTrace() The first line of output shows the same string which was returned by the toString() method for this object means Exception class name and later lines represent data previously recorded by the method fillInStackTrace().
Loggers should be used instead of printing the whole stack trace on stream. e. printStackTrace() prints a Throwable and its stack trace to stream which could inadvertently expose sensitive information. Loggers should be used instead to print Throwables, as they have many advantages.
Try:
e.printStackTrace(System.out);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With