Announcement Announcement Module
No announcement yet.
Method endpoint - java.lang.Error handling Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Method endpoint - java.lang.Error handling


    My endpoint is throwing a ClassNotFoundError. Diving into the code of int I can see that errors are re-thrown and that the throw new IllegalStateException will never be executed, since handleInvocationTargetException always rethrows the target exception. I was wondering if the code was correct and perhaps needs a look? (please see code below)

    Exceptions are OK since they get caught, logged and can be picked up by an ExceptionResolver, but Errors percolate all the way up the call stack and never get logged making it difficult to diagnose a problem.

    I can fix this myself by subclassing a spring-WS class, or catching errors myself, but I was wondering if there is a better way to do this in the framework?


       public Object invoke(Object[] args) throws Exception {
            Object endpoint = bean;
            if (endpoint instanceof String) {
                String endpointName = (String) endpoint;
                endpoint = beanFactory.getBean(endpointName);
            try {
                return this.method.invoke(endpoint, args);
            catch (InvocationTargetException ex) {
                throw new IllegalStateException("Unexpected exception thrown by method - " +
                        ex.getTargetException().getClass().getName() + ": " + ex.getTargetException().getMessage());
        private void handleInvocationTargetException(InvocationTargetException ex) throws Exception {
            if (ex.getTargetException() instanceof RuntimeException) {
                throw (RuntimeException) ex.getTargetException();
            if (ex.getTargetException() instanceof Error) {
                throw (Error) ex.getTargetException();
            if (ex.getTargetException() instanceof Exception) {
                throw (Exception) ex.getTargetException();