Just printing a stack trace is not enough. Printing an exception stack trace does not in itself mean that this is a completely wrong practice, but printing only a stack trace when an exception occurs is a problem.
Always log exceptions (using a good logging structure ), but do not expose them to the end user. And make sure to show the stack trace only in design mode.
I myself use (most of the time) logger.log(Level.SEVERE, <exception>.getMessage(), <exception>); .
when netbeans offer you to handle the exception " Surround Statement with try-catch ", if you click on it, it will throw):
try { //something need to be handle(exception that throw) } catch (SQLException ex) { Logger.getLogger(ClassName.class.getName()).log(Level.SEVERE, null, ex); }
This is better than ex.printStackTrace(); .
This can help:
Blasanka Aug 6 '17 at 9:37 on 2017-08-06 09:37
source share