Re: c++ exceptions
Re: c++ exceptions
- Subject: Re: c++ exceptions
- From: David Leimbach <email@hidden>
- Date: Tue, 6 Apr 2010 14:13:48 -0700
On Tue, Apr 6, 2010 at 2:07 PM, David Leimbach
<email@hidden> wrote:
On Mon, Apr 5, 2010 at 4:31 PM, Uli Kusterer
<email@hidden> wrote:
On 16.03.2010, at 19:40, Jens Alfke wrote:
> Ideally C++ would have the same kind of exception-checking that Java does, so you could declare a function as not throwing any exception and have the compiler enforce that for you. But C++ doesn't work that way. So you just have to be careful to wrap all your entry points, including callbacks, in try/catch blocks.
C++ supports throw specifiers, too, for both functions and methods. It's just that the defaults are different: If you don't specify a throw specifier, it will let you throw *any* exception.
C++ doesn't really work that way. The exception specifications for C++ have ended up being specified in a way that make them almost pointless.
To elaborate... You can specify that a function throws no exceptions, but the compiler is responsible for enforcing this, not the linker and it can't tell if a library called from that function throws exceptions or not... What ends up happening is the compiler has to either terminate your program, or you can catch it by writing the function "unexpected()" which is a global handler for the entire program for unexpected exceptions.
Either way, you're stuck with an abnormal return, and an exception specification that's not worth very much to anyone.
(by the way this was an Amazon interview question...)
Dave
Dave
-- Uli Kusterer
"The Witnesses of TeachText are everywhere..."
http://www.masters-of-the-void.com
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Darwin-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Darwin-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden