Topic: Temporaries and dtor exceptions
Author: Herb Sutter <HerbS@cntc.com>
Date: 1997/10/06 Raw View
I want to confirm my understanding of something. In the following code,
assume that the expression "a == b" introduces one temporary object. The
temporary is destroyed at the end of the full-expression in which it
appears. In this case, I believe that's the condition "a == b".
if( a == b )
{
cout << "something" << endl;
}
Q1: If the temporary's dtor throws, the condition's operator==() is
completely executed but the body (the cout) is not executed. Correct?
Q2: If the expression "a == b" introduces two or more temporary objects,
at least two of whose dtors throw, we get a terminate(). Correct?
Herb
---
Herb Sutter (mailto:herbs@cntc.com)
Current Network Technologies Corp. (http://www.cntc.com)
2695 North Sheridan Way, Suite 150, Mississauga ON Canada L5K 2N6
Tel 416-805-9088 Fax 905-822-3824
---
[ 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 ]
[ FAQ: http://reality.sgi.com/employees/austern_mti/std-c++/faq.html ]
[ Policy: http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu ]
Author: fjh@mundook.cs.mu.OZ.AU (Fergus Henderson)
Date: 1997/10/06 Raw View
Herb Sutter <HerbS@cntc.com> writes:
>I want to confirm my understanding of something. In the following code,
>assume that the expression "a == b" introduces one temporary object. The
>temporary is destroyed at the end of the full-expression in which it
>appears. In this case, I believe that's the condition "a == b".
Yes.
> if( a == b )
> {
> cout << "something" << endl;
> }
>
>Q1: If the temporary's dtor throws, the condition's operator==() is
>completely executed but the body (the cout) is not executed. Correct?
Yes.
>Q2: If the expression "a == b" introduces two or more temporary objects,
>at least two of whose dtors throw, we get a terminate(). Correct?
Yes.
--
Fergus Henderson <fjh@cs.mu.oz.au> | "I have always known that the pursuit
WWW: <http://www.cs.mu.oz.au/~fjh> | of excellence is a lethal habit"
PGP: finger fjh@128.250.37.3 | -- the last words of T. S. Garp.
---
[ 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 ]
[ FAQ: http://reality.sgi.com/employees/austern_mti/std-c++/faq.html ]
[ Policy: http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu ]