// get the event to handle
ExceptionQueuedEvent event = unhandled.peek();
try
{
// call its getContext() method
ExceptionQueuedEventContext context = event.getContext();
// and call getException() on the returned result
Throwable exception = context.getException();
// spec described behaviour of PreJsf2ExceptionHandler
// UpdateModelException needs special treatment here
if (exception instanceof UpdateModelException)
{
FacesMessage message = ((UpdateModelException) exception).getFacesMessage();
// Log a SEVERE message to the log
log.log(Level.SEVERE, message.getSummary(), exception.getCause());
// queue the FacesMessage on the FacesContext
UIComponent component = context.getComponent();
String clientId = null;
if (component != null)
{
clientId = component.getClientId(context.getContext());
}
context.getContext().addMessage(clientId, message);
}
else if (!shouldSkip(exception) && !context.inBeforePhase() && !context.inAfterPhase())
{
// set handledAndThrown so that getHandledExceptionQueuedEvent() returns this event
handledAndThrown = event;
// Re-wrap toThrow in a ServletException or
// (PortletException, if in a portlet environment)
// and throw it
// FIXME: The spec says to NOT use a FacesException
// to propagate the exception, but I see
// no other way as ServletException is not a RuntimeException
toThrow = wrap(getRethrownException(exception));
break;
}
else
{
// Testing mojarra it logs a message and the exception
// however, this behaviour is not mentioned in the spec
log.log(Level.SEVERE, exception.getClass().getName() + " occured while processing " +
(context.inBeforePhase() ? "beforePhase() of " :
(context.inAfterPhase() ? "afterPhase() of " : "")) +
"phase " + context.getPhaseId() + ": " +
"UIComponent-ClientId=" +
(context.getComponent() != null ?
context.getComponent().getClientId(context.getContext()) : "") + ", " +
"Message=" + exception.getMessage());
log.log(Level.SEVERE, exception.getMessage(), exception);
}
}