javanetbeans-8ioexceptionthrowableprintstacktrace

Using e.printStackTrace() in Java


Why does NetBeans IDE raise a flag on printing a Java stack trace?

try { 
    //try to do something there
} catch (IOException e) {
    //handle the exception 
    e.printStackTrace();
}

For some reason the printStackTrace is underlined in a squiggly line. When I Quick-Fix (Alt+Enter), NetBeans reports Throwable.printStackTrace() should be removed. What does this mean?


Solution

  • It is just a recommendation. In eclipse it is fine - I believe it is just the IDE telling you that there are more conventional methods of doing it, like some of the other answers. I find that it is useful for debugging, and that you should tell users when a fatal error is going to occur, to use a debug mode (like a console switch -d) to collect these logs.