Yasaman Nrn
Yasaman Nrn

Reputation: 41

Throwing exception by InvocationHandler

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

I want this lock manager to throw exceptions (e.g. DeadLockException) to the object which is calling this proxy object, and I want the caller to be able to catch this exception ,

Is that possible in Java ? if it's not what is the best method to make it somehow work

Upvotes: 4

Views: 1042

Answers (2)

Pete Verdon
Pete Verdon

Reputation: 335

It sounds like you're not declaring DeadLockException on the relevant method on the interface that your proxy implements. Your caller doesn't know that the interface implementation it's going to be given will be a proxy, it's just going on what in the interface.

Upvotes: 0

Aubin
Aubin

Reputation: 14853

If you implements InvocationHandler, you override the following method:

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

As you see, the signature of this method show the Throwable Exception may be thrown. A simple try-catch in the caller is enough.

What logic want you in the deadlock detection?

Deadlock refers to resource allocation, so where are they?

Upvotes: 2

Related Questions