InvocationHandler exception exception

I have a lock manager as a proxy class that implements InvocationHandler ,

I want this lock manager to throw exceptions (like DeadLockException ) to the object that calls this proxy object, and I want the caller to catch this exception,

Is this possible in Java? if this is not the best way to make it work somehow

+4
source share
2 answers

If you implement InvocationHandler , you override the following method:

 @Override Object invoke( Object proxy, Method method, Object[] args ) throws Throwable { throw new DeadLockException(); } 

As you can see, the signature of this method indicates that a Throwable Exception can be thrown. A simple try-catch in the caller is enough.

What logic do you need in detecting a dead end?

Deadlock refers to resource allocation, so where are they?

+2
source

It looks like you are not declaring DeadLockException about the corresponding interface method that your proxy implements. Your caller does not know that the implementation of the interface that he will provide will be a proxy server, he will just start working with the interface.

0
source

Source: https://habr.com/ru/post/1445445/


All Articles