Both HTTP errors (404, 401) and Exception messages can be displayed using the same <l:exception> tag in your error page:
The error page will not display the stack trace in any case. For the simplest case, this tag can be used in a single error page for your entire web application:
<error-page> <error-code>500</error-code> <location>/error.jsp</location> </error-page> <error-page> <error-code>400</error-code> <location>/error.jsp</location> </error-page> <error-page> <error-code>401</error-code> <location>/error.jsp</location> </error-page> <error-page> <error-code>403</error-code> <location>/error.jsp</location> </error-page> <error-page> <error-code>404</error-code> <location>/error.jsp</location> </error-page>
Exceptions are typically thrown from business logic classes, which should not know anything about the user Locale. This makes throwing locale-specific exceptions a bit tricky: they should be translated before showing to the user, but the class that is throwing the exception does not have access to the current Locale.
LocaleAwareException is a locale-specific exception that can render translated error messages.
// my own business method
public Leasing merge(Leasing leasing) {
if (somecondition) {
throw new LocaleAwareException("error.custom.nameExists").addArg("name", name);
}
}
If the business layer throws a LocaleAwareException and there is a known source form, the exception will be converted to a validation Message and the request will be forwarded to the source page as it would with any other input validation error. Otherwise it will be displayed (translated) in the standard error page.
This exception will be resolved as a response.sendError() call, but its message will be logged to the system log.
// this can be thrown from any point of your code throw new HttpException(404, "Instance with key " + id + " could not be found");
The error message is an internal detail that will be logged, but not displayed in the browser.
Errors are messages produced by the conversion or validation of user input. They are not handled as exceptions but instead get collected into a Messages object and displayed integrated in the user input form.
Error messages can be bound or unbound. Bound errors have been produced by a concrete property (invalid date, number too big, etc) and unbound errors are more generic and cannot be traced to a concrete input field ("You have exceeded your available disk space quota", for example).
By default the <l:errors> tag will only include unbound messages and bound messages for fields that are missing in the surrounding <form> tag. Other messages will appear next to the corresponding input field.
A warning will be printed to the system log if there are any validation errors not included in the rendered HTML page (for example, if the errors tag is missing).