Re: c++ exceptions
Re: c++ exceptions
- Subject: Re: c++ exceptions
- From: Jens Alfke <email@hidden>
- Date: Tue, 16 Mar 2010 08:27:53 -0700
On Mar 16, 2010, at 12:35 AM, Kevin Van Vechten wrote: The DirectoryService and Security framework implementations are notable exceptions in their extensive use of exceptions, but both are derived from a pre-Mac OS X code base. A more modern use of exceptions may be found in the dyld and llvm/clang projects.
I proudly ;) used C++ exceptions internally in the PubSub framework. But as you say, Apple’s APIs never expose C++ exceptions and almost never use Obj-C exceptions for anything but assertion failures. (The major exception is Distributed Objects, which throws exceptions on failed message-sends to remote proxy objects.)
Joel, there’s no reason you can’t use C++ exceptions. You just have to be very careful to never throw them out of your code. The worst case is where your code calls a system framework that calls back into your code, and that bit of your code throws an exception that’s caught by your outer code. The system code in the middle gets unwound without being able to clean up, which can often cause really nasty problems later on.
Another thing to watch out for is that exceptions can bloat your code if you use lots of stack-based objects with destructors. You often end up with exception-unwinding blocks that contain duplicate copies of the destructor code. I had to do some tweaking in the PubSub code to reduce the size of this stuff. It’s exacerbated because the compiler will assume that any function call, even system APIs, could throw an exception, unless it has an empty “throw ()” clause in its declaration.
—Jens |
_______________________________________________
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