Back

Explore Courses Blog Tutorials Interview Questions
0 votes
3 views
in Java by (4k points)

Well, I've tried to understand and read what could cause it but I just can't get it:

I have this somewhere in my code:

 try{

 ..

 m.invoke(testObject);

 ..

 } catch(AssertionError e){

 ...

 } catch(Exception e){

 ..

 }

Thing is that when it tries to invoke some method it throws InvocationTargetException instead of some other expected exception (specifically ArrayIndexOutOfBoundsException). As I actually know what method is invoked I went straight to this method code and added a try-catch block for the line that supposes to throw  ArrayIndexOutOfBoundsException and it really threw ArrayIndexOutOfBoundsException as expected. Yet when going up it somehow changes to InvocationTargetException and in the code above catch(Exception e), e is InvocationTargetException and not  ArrayIndexOutOfBoundsException as expected.

What could cause such behavior or how can I check such a thing?

1 Answer

0 votes
by (46k points)
You've attached an extra level of an idea by calling the program with reflection. The reflection layer covers any deviation in an InvocationTargetException, which makes you tell the distinction between an exception created by a breakdown in the reflection call (perhaps your argument list wasn't efficient, for illustration) and a mess within the method designated.

Just uncover the problem within the InvocationTargetExceptionand you'll get to the primary one

Related questions

Browse Categories

...