4

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

Arian
  • 7,397
  • 21
  • 89
  • 177

2 Answers2

2

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?

Aubin
  • 14,617
  • 9
  • 61
  • 84
  • 1.If we try to catch DeadLockException In the caller, it gives an error which says that the object may never return such an exception !! 2.How can the caller find out the type of Throwable ? is it enough to `catch` `DeadLockException` ? – Arian Nov 12 '12 at 07:15
  • 1
    Yes, because DeadlockException "is-a" Throwable (inheritance) – Aubin Nov 12 '12 at 07:16
0

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.

Pete Verdon
  • 335
  • 1
  • 10