Question about NetBeans and error.printStackTrace();

I’ve noticed for a while, but never paid any mind, that NetBeans always wants to replace:

 error.printStackTrace();

with:

 Logger.getLogger(ResourceHandler.class.getName()).log(Level.SEVERE, null, ex);

Why does NetBeans do this and what does Logger do that printStackTrace() doesn’t? In the class I took we were always told to use error.printStackTrace(); and Logger was never once mentioned.

I’ll be honest I have no real clue as I’ve never used it, but use printStackTrace() for the obvious reason; it shows you exactly where the error is. Logger I believe doesn’t do this, but again I’ve never used it so I have no idea.

It’s just a normal warning, because you should not print to the standard output(console) from production code.

Everybody uses System.out.println and printStacktrace because they are good tools while developing, but the warnings are good too, because they remind you to get rid of these calls before releasing your code.

The replacement which netbeans gives you uses the standard Java logging classes. They are quite basic and work, but especially when you are creating libs use slf4j. When you don’t know what logging is for, google yourself some nice tutorials :slight_smile:

Or maybe log4J
But, yes , you should pay attention to netbeans warning, they teach you some stuff, like , for example, i didnt know about diamond operator.

I’ll take a look at slf4j then. If you leave code that prints to a console in production code, does anything bad happen?

Not really. Just be sure to remove when you release the “final” product :stuck_out_tongue:

It doesn’t even really matter in the final product, but it’s useless code since the user can’t see it (unless running from cmd). However, it may slow down your game if you are printing many times or many different things (incrementing/decrementing numbers, etc., will slow it down a lot).

The other thing is that you think you’re telling the user an error has occurred but they actually have no idea. There is very little that is more annoying.