Topic: Re-throw ambiguity


Author: "TiTi" <titi_@skynet.be>
Date: Fri, 11 May 2001 13:38:20 GMT
Raw View
Sean Parent <sparent@adobe.com> schreef in berichtnieuws
B7177C2E.14F0D%sparent@adobe.com...
> Under VC++ (service pack 5) the following code produces the output:
>
> exception_subclass::exception_subclass()
> catch: exception_subclass
> exception_subclass::~exception_subclass()
> exception_subclass::~exception_subclass()
>
> Under Metrowerks 6 I get:
> exception_subclass::exception_subclass()
> catch: exception_subclass
> exception_subclass::~exception_subclass()

> With VC++ the second destruction is on the same object as the first and
the
> destructor is called at the end of each catch clause. At first I thought
> this was yet another bug in VC++. But reading the spec I found the
> following:
> Section 15.1 contains the clause:
> "An exception is considered finished when the corresponding catch clause
> exits"
>
> - now the question is, what defines "corresponding" for a re-throw? Can
you
> legally catch an exception that has been re-thrown before it exists the
> first catch clause? This technique for decoding an exception comes from
> Stroustrup's third edition section 14.6.3.2 (his example has the same
> problem with VC++). What is the correct behavior is in this case?

(I think) A rethrow copy constructucts the same exception on the stack to
propagate, and destructs the previous. Perhaps MetroWorks optimizes the copy
construction away (and therefore, deletion is only done once).

Didn't read the code, sorry
Cheers, and enjoy the good weather (as it is in Belgium now).
TiTi


---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html                ]





Author: Heinz Huber <hhuber@racon-linz.at>
Date: Thu, 10 May 2001 17:47:15 GMT
Raw View
Sean Parent wrote:
>
> in article 3AF79CF9.CE3559E7@racon-linz.at, Heinz Huber at
> hhuber@racon-linz.at wrote on 5/8/01 6:02 AM:
>
> > Sean Parent wrote:
> >>
> >> Under VC++ (service pack 5) the following code produces the output:
> >>
> >> exception_subclass::exception_subclass()
> >> catch: exception_subclass
> >> exception_subclass::~exception_subclass()
> >> exception_subclass::~exception_subclass()
> >>
> >> Under Metrowerks 6 I get:
> >> exception_subclass::exception_subclass()
> >> catch: exception_subclass
> >> exception_subclass::~exception_subclass()
> >>
> >> With VC++ the second destruction is on the same object as the first and the
> >> destructor is called at the end of each catch clause.
> >
> > Are you sure that indeed the same object is destroyed? Have you added trace
> > code
> > to the copy constructor of exception_subclass?
> >
> > [snip]
>
> Yes - did that. I also traced the code. This is a bug in VC++.
> Sean

Sorry, was to fast on the send button.
Heinz

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html                ]





Author: "Carl Daniel" <cpdaniel@pacbell.net>
Date: Wed, 9 May 2001 12:18:00 GMT
Raw View
"Heinz Huber" <hhuber@racon-linz.at> wrote in message
news:3AF79CF9.CE3559E7@racon-linz.at...
> Sean Parent wrote:

[snip]

> > With VC++ the second destruction is on the same object as the first and
the
> > destructor is called at the end of each catch clause.
>
> Are you sure that indeed the same object is destroyed? Have you added
trace code
> to the copy constructor of exception_subclass?
>

Actually, the OP included a copy constructor, instrumented with cout - and
it isn't called.  And yes, the 'this' pointer in both destructor calls is
the same.  I've verified the code behaves as documented by the OP - sure
looks like a bug to me.

-cd


---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html                ]





Author: Sean Parent <sparent@Adobe.COM>
Date: Wed, 9 May 2001 16:40:05 GMT
Raw View
in article 3AF79CF9.CE3559E7@racon-linz.at, Heinz Huber at
hhuber@racon-linz.at wrote on 5/8/01 6:02 AM:

> Sean Parent wrote:
>>
>> Under VC++ (service pack 5) the following code produces the output:
>>
>> exception_subclass::exception_subclass()
>> catch: exception_subclass
>> exception_subclass::~exception_subclass()
>> exception_subclass::~exception_subclass()
>>
>> Under Metrowerks 6 I get:
>> exception_subclass::exception_subclass()
>> catch: exception_subclass
>> exception_subclass::~exception_subclass()
>>
>> With VC++ the second destruction is on the same object as the first and the
>> destructor is called at the end of each catch clause.
>
> Are you sure that indeed the same object is destroyed? Have you added trace
> code
> to the copy constructor of exception_subclass?
>
> [snip]

Yes - did that. I also traced the code. This is a bug in VC++.
Sean

>
> Regards,
> Heinz
>
> ---
> [ comp.std.c++ is moderated.  To submit articles, try just posting with ]
> [ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
> [              --- Please see the FAQ before posting. ---               ]
> [ FAQ: http://www.research.att.com/~austern/csc/faq.html                ]
>

--
Sean Parent
Sr. Engineering Manager
Adobe Workgroup Services
sparent@adobe.com



======================================= MODERATOR'S COMMENT:
 Please don't overquote.

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html                ]





Author: Heinz Huber <hhuber@racon-linz.at>
Date: Tue, 8 May 2001 13:02:17 GMT
Raw View
Sean Parent wrote:
>
> Under VC++ (service pack 5) the following code produces the output:
>
> exception_subclass::exception_subclass()
> catch: exception_subclass
> exception_subclass::~exception_subclass()
> exception_subclass::~exception_subclass()
>
> Under Metrowerks 6 I get:
> exception_subclass::exception_subclass()
> catch: exception_subclass
> exception_subclass::~exception_subclass()
>
> With VC++ the second destruction is on the same object as the first and the
> destructor is called at the end of each catch clause.

Are you sure that indeed the same object is destroyed? Have you added trace code
to the copy constructor of exception_subclass?

[snip]

Regards,
Heinz

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html                ]





Author: Sean Parent <sparent@adobe.com>
Date: Fri, 4 May 2001 21:23:11 GMT
Raw View
Under VC++ (service pack 5) the following code produces the output:

exception_subclass::exception_subclass()
catch: exception_subclass
exception_subclass::~exception_subclass()
exception_subclass::~exception_subclass()

Under Metrowerks 6 I get:
exception_subclass::exception_subclass()
catch: exception_subclass
exception_subclass::~exception_subclass()

With VC++ the second destruction is on the same object as the first and the
destructor is called at the end of each catch clause. At first I thought
this was yet another bug in VC++. But reading the spec I found the
following:

Section 15.1 contains the clause:

"An exception is considered finished when the corresponding catch clause
exits"

- now the question is, what defines "corresponding" for a re-throw? Can you
legally catch an exception that has been re-thrown before it exists the
first catch clause? This technique for decoding an exception comes from
Stroustrup's third edition section 14.6.3.2 (his example has the same
problem with VC++). What is the correct behavior is in this case?

The msdn knowledge base doesn't have anything on this issue (that I can
find).

Sean

----
#include <exception>
#include <iostream>
#include <typeinfo>


class exception_subclass : public std::exception
    {
public:
    exception_subclass()
        { std::cout << typeid(*this).name() << "::exception_subclass()" <<
std::endl; }
    exception_subclass(const exception_subclass&)
        { std::cout << typeid(*this).name() << "::exception_subclass(const
exception_subclass&)" << std::endl; }

    ~exception_subclass()
        { std::cout << typeid(*this).name() << "::~exception_subclass()" <<
std::endl; }
    };

static void decode_exception()
    {
    try
        {
        throw;
        }
    catch (const exception_subclass& exception)
        {
        std::cout << "catch: " << typeid(exception).name() << std::endl;
        }
    catch (const std::exception& exception)
        {
        std::cout << "catch: " << typeid(exception).name() << std::endl;
        }
    catch (...)
        {
        std::cout << "catch: ..." << std::endl;
        }
    }

int main()
    {
    try
        {
        throw exception_subclass();
        }
    catch (...)
        {
        decode_exception();
        }


    return 0;
    }

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html                ]