Go Back   ZeroC Forums > Help Center

Reply
 
LinkBack Thread Tools Rate Thread Display Modes
  #1 (permalink)  
Old 06-25-2007
HpGisler HpGisler is offline
Registered User
 
Name: Hanspeter Gisler
Organization: Sensirion
Project: Rigi
 
Join Date: May 2006
Posts: 6
Best practice for exception mapping

Hello

I've got a basic question regarding the usage of exceptions. Probably, it's a little naive anyway.

Ok.

Here is the situation:

We've got a C++ server side application and a C# client side application.

For error handling, we defined in slice some exceptions which can be thrown by the server side application and which can be catched by the client side application.

We are interested in a simple text based info in these exceptions, so we've added a string property into the slice exception definition accordingly.


Now to the question:

In the end, we simply would like to put the error-string into a standard C#-base-type-exception.

Is the manual wrapping of each proxy-method-call into a try-catch statement the only reasonable way to get the string out of the ice-exception and into a client side exception (re-throwing it in the catch clause), or is there a more elegant way to achieve this?


Thanks very much for your professional inputs.

Regards
hp.
Reply With Quote
  #2 (permalink)  
Old 06-25-2007
michi's Avatar
michi michi is offline
ZeroC Staff
 
Name: Michi Henning
Organization: ZeroC
Project: Ice
 
Join Date: Feb 2003
Location: Brisbane, Australia
Posts: 931
Hmmm, let me make sure I understand you correctly. You have a Slice exception that is thrown by an operation. When the exception is thrown, you don't want the Slice exception to propagate higher up the call stack. Instead, you want to throw a different exception, not defined in Slice. Something like:
Code:
try {
    proxy.operation();
} catch (SliceException) {
    throw new NonSliceException();
}
You also say that the Slice exception contains an error string that you would like to be in the non-Slice exception. Something like:
Code:
try {
    proxy.operation();
} catch (SliceException ex) {
    throw new NonSliceException(ex.text);
}
As you can see, whether the string is there or not makes little difference. The only way to "translate" one exception into another is to catch the exception and throw a different one, which requires try-catch blocks.

You need not necessarily do this for every invocation. Instead, you can most likely install the try-catch blocks higher up in the call hierarchy and deal with the exception there, so you do not clutter the code with endless identical try-catch blocks. But, somewhere, you will need to do this in order to throw a different exception than is received over the wire.

Cheers,

Michi.
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
Mapping Exception ganzuoni Comments 2 02-14-2008 07:39 AM
Have IceUtil::Exception inherit from std::exception? bpolivka Comments 2 12-13-2006 11:52 AM
Server versioning best practice ctennis Help Center 0 12-11-2006 12:14 PM
Which language mapping(s) do you use? marc Comments 12 05-31-2006 07:19 AM
C mapping colding Comments 4 03-31-2005 05:48 AM


All times are GMT -4. The time now is 12:22 AM.


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