Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 03-27-2008, 12:19 PM
rjuyal's Avatar
Member
 
Join Date: Mar 2008
Location: Delhi, India
Posts: 92
rjuyal is on a distinguished road
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...
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 04-04-2008, 09:01 PM
Member
 
Join Date: Feb 2008
Posts: 13
new_2_java is on a distinguished road
Make sure your HMSException is extending Exception.
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 04-07-2008, 07:11 AM
rjuyal's Avatar
Member
 
Join Date: Mar 2008
Location: Delhi, India
Posts: 92
rjuyal is on a distinguished road
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
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 04-07-2008, 12:04 PM
Member
 
Join Date: Apr 2008
Posts: 2
spikey is on a distinguished road
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?
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 04-07-2008, 12:07 PM
rjuyal's Avatar
Member
 
Join Date: Mar 2008
Location: Delhi, India
Posts: 92
rjuyal is on a distinguished road
wooo
OMG! sounds good, let me try this.

Thanks Spikey
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Method Help pringle New To Java 4 04-16-2008 02:23 PM
[/WEB-INF/applicationContext-dao.xml]: Invocation of init method Heather Database 2 06-12-2007 05:33 PM
method not abstract, does not override actionperformed method. Theman New To Java 1 05-08-2007 07:13 AM


All times are GMT +3. The time now is 05:35 PM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org