GCC begins move to C++
GCC begins move to C++
Posted Jun 2, 2010 1:31 UTC (Wed) by dvdeug (guest, #10998)In reply to: GCC begins move to C++ by dgm
Parent article: GCC begins move to C++
Posted Jun 2, 2010 13:53 UTC (Wed)
by dgm (subscriber, #49227)
[Link] (3 responses)
You would be surprised. I recommend you to read this http://www.gotw.ca/gotw/020.htm
In this concrete example:
1. c() can indeed throw an exception in the code, but can also propagate uncaught exceptions from any code called within, possibly including constructors.
AFAIK, the only thing that cannot throw is "b".
Posted Jun 2, 2010 14:37 UTC (Wed)
by mjthayer (guest, #39183)
[Link]
I think the OP was talking about code directly converted from C, so those things should not apply.
Posted Jun 3, 2010 0:24 UTC (Thu)
by dvdeug (guest, #10998)
[Link] (1 responses)
a = copy_foo (add_foo (b, c()));
in C. If C++ would have thrown an exception, then a will have an error code in it (and a will have to support error values, and that value will have to be checked just like you have to catch an exception), a will have trash in it (and you'll have to check it--if you can) or the whole thing will crash, like if copy_foo assumes that add_foo can't return errors or trash.
Posted Jun 3, 2010 16:31 UTC (Thu)
by dgm (subscriber, #49227)
[Link]
That's basically the problem. Adding exceptions to an established code base changes basic assumptions programmers would probably have made (nobody in his right mind would lose time writing exception-safe code if your language has no exceptions!).
GCC begins move to C++
2. + can be an overloaded operator, and thus can also throw.
3. = can need to create a temporary object, whose constructor can also throw.
GCC begins move to C++
> 1. c() can indeed throw an exception in the code, but can also propagate uncaught exceptions from any code called within, possibly including constructors.
> 2. + can be an overloaded operator, and thus can also throw.
> 3. = can need to create a temporary object, whose constructor can also throw.
GCC begins move to C++
GCC begins move to C++