Examples of CatchHandler


Examples of com.blazebit.cdi.exception.annotation.CatchHandler

  public Object handle(InvocationContext ic) throws Exception {
    Method m = ic.getMethod();
    Object targetObject = ic.getTarget();
    Class<?> targetClass = targetObject == null ? m.getDeclaringClass()
        : targetObject.getClass();
    CatchHandler exceptionHandlerAnnotation = AnnotationUtils
        .findAnnotation(m, targetClass, CatchHandler.class);
    Exception unexpectedException = null;

    if (exceptionHandlerAnnotation == null) {
      throw new IllegalStateException(
          "The interceptor annotation can not be determined!");
    }

    CatchHandling[] exceptionHandlingAnnotations = exceptionHandlerAnnotation
        .value();
    Class<? extends Throwable>[] unwrap = exceptionHandlerAnnotation
        .unwrap();

    try {
      return ic.proceed();
    } catch (Exception ex) {
      if (!contains(unwrap, InvocationTargetException.class)) {
        unwrap = Arrays.copyOf(unwrap, unwrap.length + 1);
        unwrap[unwrap.length - 1] = InvocationTargetException.class;
      }

      // Unwrap Exception if ex is instanceof InvocationTargetException
      Throwable t = ExceptionUtils.unwrap(ex,
          InvocationTargetException.class);
      boolean exceptionHandled = false;
                        boolean cleanupInvoked = false;

      if (exceptionHandlingAnnotations.length > 0) {
        for (CatchHandling handling : exceptionHandlingAnnotations) {
          if (handling.exception().isInstance(t)) {
            try {
              handleThrowable(t);
              exceptionHandled = true;
            } catch (Exception unexpected) {
              unexpectedException = unexpected;
            }

            // Only invoke cleanup declared at handling level
            if (!handling.cleanup().equals(Object.class)) {
                                                        cleanupInvoked = invokeCleanups(targetClass, targetObject,
                                                                    handling.cleanup(), t);
            }

            break;
          }
        }
      }

      // Handle the default exception type if no handlings are
      // declared or the handling did not handle the exception
      if (!exceptionHandled) {
        if (exceptionHandlerAnnotation.exception().isInstance(t)) {
          try {
            handleThrowable(t);
            exceptionHandled = true;
          } catch (Exception unexpected) {
            unexpectedException = unexpected;
          }

          if (!exceptionHandlerAnnotation.cleanup().equals(
              Object.class) && !cleanupInvoked) {
            if(!cleanupInvoked) {
                                                    invokeCleanups(targetClass, targetObject,
                exceptionHandlerAnnotation.cleanup(), t);
                                                }
          }
        }
      }
View Full Code Here

Examples of com.blazebit.cdi.exception.annotation.CatchHandler

  public Object handle(InvocationContext ic) throws Exception {
    Method m = ic.getMethod();
    Object targetObject = ic.getTarget();
    Class<?> targetClass = targetObject == null ? m.getDeclaringClass()
        : targetObject.getClass();
    CatchHandler exceptionHandlerAnnotation = AnnotationUtil
        .findAnnotation(m, targetClass, CatchHandler.class);
    Exception unexpectedException = null;

    if (exceptionHandlerAnnotation == null) {
      throw new IllegalStateException(
          "The interceptor annotation can not be determined!");
    }

    CatchHandling[] exceptionHandlingAnnotations = exceptionHandlerAnnotation
        .value();

    try {
      return ic.proceed();
    } catch (Exception ex) {
      // Unwrap Exception if ex is instanceof InvocationTargetException
      Throwable t = ExceptionUtil.unwrapInvocationTargetException(ex);
      boolean exceptionHandled = false;

      if (exceptionHandlingAnnotations.length > 0) {
        for (CatchHandling handling : exceptionHandlingAnnotations) {
          if (handling.exception().isInstance(t)) {
            try {
              handleThrowable(t);
              exceptionHandled = true;
            } catch (Exception unexpected) {
              unexpectedException = unexpected;
            }

            // Only invoke cleanup declared at handling level
            if (!handling.cleanup().equals(NullClass.class)) {
              invokeCleanups(targetClass, targetObject,
                  handling.cleanup());
            }

            break;
          }
        }
      }

      // Handle the default exception type if no handlings are
      // declared or the handling did not handle the exception
      if (!exceptionHandled) {
        if (exceptionHandlerAnnotation.exception().isInstance(t)) {
          try {
            handleThrowable(t);
            exceptionHandled = true;
          } catch (Exception unexpected) {
            unexpectedException = unexpected;
          }

          if (!exceptionHandlerAnnotation.cleanup().equals(
              NullClass.class)) {
            invokeCleanups(targetClass, targetObject,
                exceptionHandlerAnnotation.cleanup());
          }
        }
      }

      if (!exceptionHandled) {
View Full Code Here

Examples of org.jboss.as.cli.handlers.trycatch.CatchHandler

        cmdRegistry.registerHandler(new BatchMoveLineHandler(), "move-batch-line");
        cmdRegistry.registerHandler(new BatchEditLineHandler(), "edit-batch-line");

        // try-catch
        cmdRegistry.registerHandler(new TryHandler(), "try");
        cmdRegistry.registerHandler(new CatchHandler(), "catch");
        cmdRegistry.registerHandler(new FinallyHandler(), "finally");
        cmdRegistry.registerHandler(new EndTryHandler(), "end-try");

        // if else
        cmdRegistry.registerHandler(new IfHandler(), "if");
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.