[omniORB] Exception in constructor

Randy Shoup rshoup@tumbleweed.com
Mon, 30 Nov 1998 11:41:44 -0800


Martin Renner wrote:
> 
> Hi.
> 
> I have this tiny CORBA-interface:
> 
> ----+----+----
> interface test1 {};
> ----+----+----
> 
> Now, I want to throw an exception in the constructor of the C++ implementation:
> 
> ----+----+----
> class EXCEP {};
> 
> class test1_i : public virtual _sk_test1
> {
> public:
>     test1_i() { throw EXCEP(); }
> };
> 
> [...]
> {
>    test1_i* t1;
>    try {
>        t1 = new test1_i();
>    }
>    catch (EXCEP&)
>    {
>    }
> }
> ----+----+----
> 
> When I execute this, my application does not jump into the catch-block. It
> aborts in the destructor of the base class (class "test1" in file
> "test1.hh"). Is this a bug in omniORB or am I just too stupid to use
> exceptions??
> 
> My environment:
>   NT 3.0
>   MSVC 5.0 (with SP3)
>   omniORB 2.6.1

You have actually hit a bug in MSVC, in how it handles destruction of a
virtual base class when an exception is thrown in a constructor.  See 

http://www.orl.co.uk/omniORB/archives/1998-09/0015.html

for a sketch of a workaround.

-- Randy
_________________________________________________________________  
Randy Shoup                                     (650)569-3682  
Principal Engineer                              rshoup@tumbleweed.com  
Tumbleweed Software Corporation