Using e.printStackTrace() in Java

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!


Solution 1:

Try:

e.printStackTrace(System.out);

Solution 2:

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.

Solution 3:

It's probably because printStackTrace() doesn't really handle the error as much as it just dumps the stack in the console. It acts as a placeholder until you replace it with proper error handling (if it is needed at all) and replace the output with a logger of some sort.