4 Replies Latest reply: Apr 17, 2012 3:43 AM by Ivo Maixner RSS

Solder exceptions: support handling unexpected exceptions

Ivo Maixner Newbie

Should there be a way to handle exceptions not handled by any other handler?


public class ExceptionHandler {
     public void unexpectedException(@Handles CaughtException<Throwable> event) {
          if (!event.isMarkedHandled()) {
               log.error("Unexpected exception", event.getException());
               messages.error(new BundleKey(MESSAGE_BUNDLE, "unexpected.exception"));
      ... other, specific handlers... like e.g.:
     public void optimisticLockException(
               @Handles CaughtException<OptimisticLockException> event) {
          messages.error(new BundleKey(MESSAGE_BUNDLE, "optimistic.lock.exception"));


This code above in the unexpectedException() however gets in the way when a specific handler wants to respond to a non-root cause exception, which is the case with OptimisticLockException, which wraps a root cause Hibernate exception. During the DEPTH_FIRST traversal, Solder first resolves the root cause Hibernate exception up its class hierarchy to Throwable and so the unexpectedException() handler gets invoked before the optimisticLockException() handler gets a chance to handle the event.


Some ideas:

  • an UnhandledException event fired from ExceptionHandlerDispatch.executeHandlers as a last chance to handle it before re-throwing it as unhandled
  • a third traversal type - after BREADTH_FIRST and DEPTH_FIRST