Go Back   ZeroC Forums > Help Center

Reply
 
LinkBack Thread Tools Rate Thread Display Modes
  #1 (permalink)  
Old 06-14-2007
AaronIct AaronIct is offline
Registered User
 
Name: wang yang
Organization: ICT
Project: DBroker
 
Join Date: Apr 2005
Location: China
Posts: 9
Send a message via MSN to AaronIct
-->
why client cannot catch user-defined exception in AMI mode?

I define an interface :

interface myI {
["ami"] int myOP(string s) throw myEx ;
}


but I just find ice_exception(const ::Ice::Exception&)

How could I catch "myEx" in callback object?

Why not ice_exception(const myEx&)??

my env : c++ , Ice-2.1.0 , linux

many thanks !
Reply With Quote
  #2 (permalink)  
Old 06-14-2007
marc's Avatar
marc marc is offline
ZeroC Staff
 
Name: Marc Laukien
Organization: ZeroC, Inc.
Project: The Internet Communications Engine
 
Join Date: Feb 2003
Location: Florida
Posts: 1,781
All exceptions are derived from Ice::Exception, including your own user exceptions. In your implementation of ice_exception(), you can down-cast the exception to your derived type to both check whether the exception that is raised is indeed your user exception, as well as to get the actual value of your exception. An alternative implementation is to re-throw the exception in ice_exception() with ex->ice_throw(), and then to use a catch() for your user exception.
Reply With Quote
  #3 (permalink)  
Old 06-14-2007
marc's Avatar
marc marc is offline
ZeroC Staff
 
Name: Marc Laukien
Organization: ZeroC, Inc.
Project: The Internet Communications Engine
 
Join Date: Feb 2003
Location: Florida
Posts: 1,781
By the way, Ice 2.1.0 is quite old. I highly recommend to upgrade.
Reply With Quote
  #4 (permalink)  
Old 06-15-2007
AaronIct AaronIct is offline
Registered User
 
Name: wang yang
Organization: ICT
Project: DBroker
 
Join Date: Apr 2005
Location: China
Posts: 9
Send a message via MSN to AaronIct
-->
ice_throw does not work

Quote:
Originally Posted by marc View Post
All exceptions are derived from Ice::Exception, including your own user exceptions. In your implementation of ice_exception(), you can down-cast the exception to your derived type to both check whether the exception that is raised is indeed your user exception, as well as to get the actual value of your exception. An alternative implementation is to re-throw the exception in ice_exception() with ex->ice_throw(), and then to use a catch() for your user exception.
I re-throw the exception with ex->ice_throw.

try{
ex->ice_throw();
}
catch(myEx e)
{
//go to bed
}
catch(::Ice::Exception e)
{
//watch TV
}

I have never gone to bed ....

can you give a sample code ?
Reply With Quote
  #5 (permalink)  
Old 06-15-2007
benoit's Avatar
benoit benoit is online now
ZeroC Staff
 
Name: Benoit Foucher
Organization: ZeroC, Inc.
Project: Ice
 
Join Date: Feb 2003
Location: Rennes, France
Posts: 1,534
Hi,

This should work. Try for example to modify the client from the demo/Ice/async demo (available in Ice 3.2.0). Change the implementation of the AMI callback ice_exception method to:

Code:
    virtual void ice_exception(const Ice::Exception& ex)
    {
        try
        {
            ex.ice_throw();
        }
        catch(const RequestCanceledException&)
        {
            cerr << "request failed!" << endl;
        }
        catch(const Ice::Exception& ex)
        {
            cerr << "sayHello AMI call failed:\n" << ex << endl;
        }
    }
Then run the client against the server and type "d" followed by "s" to shutdown server and get it to cancel the delayed request. You'll see that the exception is correctly catch by the client and the client will display "request failed!".

Also, note that you should catch exceptions by reference not value, so your code should look like the following:
Code:
try{
ex.ice_throw();
}
catch(const myEx& e)
{
//go to bed
}
catch(const ::Ice::Exception& e)
{
//watch TV
}
Cheers,
Benoit.
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes Rate This Thread
Rate This Thread:

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 Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Sending Exception To Client from AMI jesse Help Center 1 04-25-2007 06:36 PM
How to catch ConnectionLostConnection exception in cpp? Vitaly Berov Help Center 5 02-27-2007 08:03 AM
Problems with user-defined types davidcr1983 Help Center 3 07-14-2006 03:12 PM
icepack client cannot catch exception supperstar Help Center 6 09-08-2005 08:56 AM
some problem about user exception fishinmoon Help Center 1 09-08-2004 02:37 PM


All times are GMT -4. The time now is 11:20 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0
(c) 2008 ZeroC, Inc.