Results 1 to 5 of 5
Thread: HELP: Method Invocation
- 03-27-2008, 11:19 AM #1
HELP: Method Invocation
Hi All,
i am using
method.invoke method to invoke some methods
For Eg:
if ( i == 1 )
// get the method fun1 ( ... ) in method
method.invoke ( this, args... );
if ( i == 2 )
// get the method fun2 ( ... ) in method
method.invoke ( this, diffArgs... );
everything is working fine. It is calling the function , now i am throwing an user created Exception ( HMSException ) from the method fun1 ( ... ).
but when i but a try catch block in
try{
method.invoke ( this, args... );
}catch ( HMSException e ) {
print ( "Never got Caught" );
}
i am unable to catch the exception.
try{
method.invoke ( this, args... );
}catch ( Exception e ) {
print ( "Now it catches the correct Exception means same message." );
}
It works fine now, but the game is i want to catch the Exception which i haev thrown not the JAVA Exception...
- 04-04-2008, 08:01 PM #2
Member
- Join Date
- Feb 2008
- Posts
- 60
- Rep Power
- 0
Make sure your HMSException is extending Exception.
- 04-07-2008, 06:11 AM #3
thanks
thanks for the reply.
I have already extended the Exception class, but still it is of no use.
it is like, i am using
try{
method.invoke ( ); // method points to my method which throws HMSException
}catch ( Exception e ) { } // works fine
try{
method.invoke ( ); // method points to my method which throws HMSException
}catch ( HMSException e ) { } // doesn' works
Thanks in advance
- 04-07-2008, 11:04 AM #4
Member
- Join Date
- Apr 2008
- Posts
- 2
- Rep Power
- 0
Your HMSException is not a checked exception on Method.invoke so you will be unable to catch it.
If the invoking method (fun1) throws an exception, invoke with catch this and will in turn throw a InvocationTargetException with your HMSException as the cause.
Hope that helps?
- 04-07-2008, 11:07 AM #5
Similar Threads
-
method not abstract, does not override actionperformed method.
By Theman in forum New To JavaReplies: 2Last Post: 03-26-2010, 05:12 PM -
Method Help
By pringle in forum New To JavaReplies: 4Last Post: 04-16-2008, 01:23 PM -
[/WEB-INF/applicationContext-dao.xml]: Invocation of init method
By Heather in forum JDBCReplies: 2Last Post: 06-12-2007, 04:33 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks