@ExceptionHandler

Target: Class annotated with @StageDefinition or an attribute of a POJO annotated with @StageDefinition.

Description: Declares the current stage as the stage that will manage all raised exceptions defined in the exceptions parameter.
With this definition, DiF will automatically redirect the application execution flow to this page, whenever and wherever any exception that is an instance of any of the exception classes given.

JavaDoc: Click here

Attributes:

Name Description Data type Required Default value
exceptions Comma-separated list of the FQNs of the handled exceptions. String No java.lang.Exception

Example:

@StageDefinition(name = "Database Error Stage", service = "errorhandlingservice")
@ExceptionHandler(exceptions = "org.hibernate.HibernateException")
@View(target = "internal/databaseError.jsp")
@DispatcherMode(authenticate = false, authorize = false)
public class HibernateErrorStage extends AbstractErrorHandler {

    public String getMessageContent()
    {
        Exception exception = (Exception) context.getRequest().getAttribute(
                ExceptionHandlers.RAISED_EXCEPTION_ATTRIBUTE);
        HibernateException exception = getExceptionWithinStack(HibernateException.class, exception);
        
        if (exception == null)
            return "No Hibernate message found!";
        else
            return exception.getMessage();
    }
}

You can see the optional usage of the DiF provided AbstractErrorHandler, that provides the getExceptionWithinStack method for crawling inside the exception stack and returning the handled exception that triggered this handler.

See also:

Back to annotation reference