简体   繁体   中英

Why does proceed() give an error

I have the following aspect:

aspect NullifyNoResultException {

    Object around(..) : execution(public Object com.example.*.*(..) {
        try { return proceed();    
            } catch (NoResultException e) { 
                return null;
            }                  
        }
    }
}

For some reason the call to proceed gives an error in Eclipse:

The method proceed() is undefined for the type NullifyNoResultException

When I build in maven -> mvn install I get no errors. But that makes no sense because I'm still missing an import for the NoResultException so maven should complain about that.
Instead it just builds and does not complain.

How do I get Eclipse to stop complaining about the proceed() ?
and how do I get this aspect to build?

I found a few syntax errors in your code example. When I correct them, the following example runs fine. BTW, I defined my own NoResultException because I have no Java EE installed.

package javax.persistence;

public class NoResultException extends RuntimeException {
    private static final long serialVersionUID = 1L;
}
package com.example.stackoverflow;

import javax.persistence.NoResultException;

public class Application {
    public static void main(String[] args) {
        Application app = new Application();
        System.out.println(app.valueReturningMethod(1, "two"));
        System.out.println(app.exceptionThrowingMethod(1, "two"));
    }

    public Object valueReturningMethod(int i, String string) {
        return "normal result";
    }

    public Object exceptionThrowingMethod(int i, String string) {
        throw new NoResultException();
    }
}
package com.example.stackoverflow;

import javax.persistence.NoResultException;

aspect NullifyNoResultException {
    Object around() : execution(public Object com.example..*(..)) {
        try {
            return proceed();
        } catch (NoResultException e) {
            return null;
        }
    }
}

The output is as expected:

normal result
null

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM