Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: Trouble with C++ exceptions, code



But this uncaughtHandler DOES terminate execution of the program without
returning to the caller in all cases. So how does it not satisfy the C++
standard requirement?

I've been having the same problem on Darwin/MacOSX. However, I've noticed
that it seems to work fine if the entire program is one statically linked
executable, but it always fails if there are dynamic libraries involved.
(In particular, where the uncaughtHandler itself is in a dynamic library.)

The same code works fine for me under Solaris/Intel 8 and GCC 3.1 regardless
of whether or not dynamic libraries are used.

-John DeNisi


-----Original Message-----
From: Matt Austern [mailto:email@hidden]
Sent: Monday, July 28, 2003 12:57 PM
To: Bjvrn Giesler
Cc: email@hidden
Subject: Re: Trouble with C++ exceptions, code

On Monday, July 28, 2003, at 02:47 AM, Bjvrn Giesler wrote:

> void uncaughtHandler(void)
> {
> try {
> printf("Re-throwing.\n");
> throw;
> } catch(MyException& e) {
> printf("MyException\n");
> abort();
> } catch(...) {
> printf("Unknown\n");
> abort();
> }
> }
...
> int main(int argc, char **argv)
> {
> std::set_terminate(uncaughtHandler);
> return myFunction();
> }

You shouldn't do this. The C++ standard says (18.6.3.1, paragraph 2)
that a terminate handler "shall terminate execution of the program
without returning to the caller". The implementation relies on this
function meeting this requirement. Your uncaughtHandler doesn't
satisfy it.

--Matt
_______________________________________________
darwin-development mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/darwin-development
Do not post admin requests to the list. They will be ignored.
_______________________________________________
darwin-development mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/darwin-development
Do not post admin requests to the list. They will be ignored.



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.