Displaying error messages in a web application

1

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.

    
asked by anonymous 04.04.2014 / 19:21

1 answer

3

It's all a matter of common sense, Geison. I do not know if I understood your question exactly, but let's take a break.

  

How best to display the exceptions for this case   specific? It's okay to take exceptions and customize your messages   as in the example below?

Perhaps an error message when connecting to the database is not interesting to the user. He does not want to know technically what happened, a lot of people do not even know what a database is, for example. So in terms of application error logging, the more specific it is, the better we developers have access to it. As for what will appear to the user we have to evaluate the following: is an error that should be handled or a "choke", an unexpected error?

In the first case, at the beginning of a development, we generally do not have all possible errors. Even exception handling goes through a period of maturity during software development. As we are developing and encountering errors, we treat it and the user thus has a friendly error message, be it a mandatory field not filled out or an unfulfilled business rule. This type of message should usually be prominently displayed on the screen that the user is on.

In the second case, what I particularly do is treat it as a "fatal error". I see a default system error screen.

Generally, I have an exception type for the system, which I use to "map" known errors, which should be handled. In an exception barrier I capture this type of exception and display for the user. Any other exception that is still unknown or is the result of a "choke" of the system, is displayed on a unique error screen.

I was able to clarify your doubt?

Hugs,

    
04.04.2014 / 21:27