Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to inspect a method using reflection

public void foo(){
    throw new Exception("foo");
}


public void bar(){
    foo();
}

Is it possible to inspect the method bar() in order to know that foo() is called without a try catch inside bar()?

like image 440
JohnJohnGa Avatar asked Dec 27 '22 13:12

JohnJohnGa


1 Answers

You may be interested in wrapping the whole class inside a Proxy and watch it with an InvocationHandler:

http://www.javalobby.org/java/forums/t18631.html

Your InvocationHandler would do something special if it sees that "foo" is called immediatly after "bar", I guess.

like image 116
Vicente Plata Avatar answered Dec 30 '22 02:12

Vicente Plata