I developed a simple web application to study some concepts related to Servlet
among others. I mapped the web.xml
file of my application to display página de erro
if any exception occurs.
Doubt: How best to display the exceptions for this particular case? Is it okay to take the exceptions and customize your messages as in the example below?
For a failure to connect to the database:
public Connection getConnection() {
try {
DriverManager.registerDriver(new com.mysql.jdbc.Driver());
return DriverManager.getConnection(
"jdbc:mysql://localhost:3306/MYDB", "root", "");
} catch (SQLException e) {
throw new ConnectionException("Falha na conexão com o banco de dados");
}
}
Is there good practice in presenting error messages to the user?
EDIT
Here is my error-handling page (half a little bit still, but waiting for help to become more serious):
<html>
<body>
<h1>Falha do sistema</h1>
Descrição: ${pageContext.errorData.throwable.message}
</body>
</html>
In this case, will% cos_de% need to always give try / catch in order to customize the exception message (throw new MinhaException)? (1)
How can I make my messages dynamic without giving try / catch? (2)
Is there any way I can intercept the exceptions and display a different message for each type?
NOTE: It is important to realize that the question arises from using the (3)
variable to print the error.