[omniORB] Throw Exceptions
Visscher, Bruce
VISSCHB@RJRT.com
Wed, 19 Dec 2001 14:52:28 -0500
This is a multi-part message in MIME format.
--------------InterScan_NT_MIME_Boundary
Content-Type: text/plain;
charset="koi8-r"
I'll take a stab at this.
First, don't confuse CORBA raises clause with C++ throw specifications.
There are those that would argue that you should never use C++ throw specifications. I can see their point given that the only
thing a C++ throw specification accomplishes is making your program more likely to call terminate which is usually not desirable.
Whether this is better than what might happen otherwise is a matter of debate (an unhandled exception propagating all the way out
and then causing main to crash might leave fewer clues than a terminate call that leaves behind a stack trace, core dump, etc.).
A CORBA raises clause is very different. The only way to propogate an exception "accross the wire" to a client is by using a raises
clause. So, raises clauses are less controversial since it is clear that the only way to be able to throw an exception to a client
is via the raises clause. Think about the ORB run time for a moment. How else can it accomplish this propogation unless you tell
it precisely which exceptions your method is allowed to throw?
Another way to look at it is to recognise that the default (when none is specified) throw specificiation is to allow any exception.
The default (when none is specified) raises specification is to allow none.
I think it is actually this last observation that reveals the source of the problem you are having. Ignoring some basic syntactic
and sematic problems (A isn't derived from B, how can it call a B method? Does A "have a" B?), you have stated that B::b() does not
throw any exceptions. Then you ask how to handle it if it does. You have contradicted yourself. Go back and decide whether it
really makes sense for B::b() to throw an exception and modify either your C++ code or your IDL or both.
HTH,
Bruce
> -----Original Message-----
> From: Onopin Mikhail [mailto:kool@garant.ru]
> Sent: Wednesday, December 19, 2001 10:36 AM
> To: omniorb-list@uk.research.att.com; tao-users@cs.wustl.edu
> Subject: [omniORB] Throw Exceptions
>
>
> Hello all!
>
> idl code:
>
> exception Ex {};
>
> interface A{
> void a();
> };
> interface B{
> void b();
> };
> interface C{
> void c() raises Ex;
> };
>
> My problem in comment in follow cpp code:
>
> void A::a()
> {
> // Here i want to catch Ex wich throws C::c().
> try {
> B::b();
> } catch(Ex) {
> ...
> }
> }
>
> void B::b()
> {
> // Here i must catch exception (because the method C::c()
> declared as
> thrown), but i don't want it!
> C::c();
> }
>
> void C::c() throw Ex
> {
> throw new Ex();
> }
>
> Posible solution for this, is write new code:
>
> void B::b() throw CORBA::UserException
> {
> // Now ok! Because this method declared as thrown base
> class of Ex!
> C::c();
> }
>
> But in IDL i can't write:
> interface B{
> void b() raises CORBA::UserException;
> };
>
>
>
>
--------------InterScan_NT_MIME_Boundary
Content-Type: text/plain;
name="InterScan_Disclaimer.txt"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
filename="InterScan_Disclaimer.txt"
CONFIDENTIALITY NOTE: This e-mail message, including any attachment(s), contains information that may be confidential, protected by the attorney-client or other legal privileges, and/or proprietary non-public information. If you are not an intended recipient of this message or an authorized assistant to an intended recipient, please notify the sender by replying to this message and then delete it from your system. Use, dissemination, distribution, or reproduction of this message and/or any of its attachments (if any) by unintended recipients is not authorized and may be unlawful.
--------------InterScan_NT_MIME_Boundary--