It is "wrong" to use any type of output that demonstrates what it has on your system, such as printStackTrace
for example. Because, in addition to the messy, ugly screen and the user does not understand anything, someone more understood can see the names of classes, methods, and depending on the case up version and type of server that is being used, which is a failure of security.
System.out
is not recommended because it will print in the application's default output , and this output is often disregarded or even disabled. If you make a java -jar app.jar &
or run the application as serviço
, this output will no longer exist.
If you are doing a WEB application, or something complex, the ideal is to do a LOG with the error and alert the user with some treated message, and if possible a code, type an alert javascript itself.
For a basic% method, System.out is OK as long as the messages are handled and you do not let a main
pass.
A better deal would be to use LOGS, such as log4j for example, and use functions like stackTrace
or log.error("Mensagem", Exception)
or log.warn()
, etç, depending on what you want to log in.