Re: c++ exceptions
Re: c++ exceptions
- Subject: Re: c++ exceptions
- From: Kevin Van Vechten <email@hidden>
- Date: Tue, 16 Mar 2010 00:35:47 -0700
Generally speaking, most Apple authored code avoids the use of exceptions for flow control and instead reserves exceptions for programmatic errors (i.e. array index out of bounds), especially in libraries and frameworks. I'm not aware of any instances of exceptions being exposed across API boundaries on Mac OS X.
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.
Kevin
On Mar 16, 2010, at 12:25 AM, Stephen J. Butler wrote:
> On Tue, Mar 16, 2010 at 2:12 AM, Joel Reymont <email@hidden> wrote:
>> Are there examples of Apple using C++ exceptions in their code?
>>
>> Anything at http://opensource.apple.com?
>
> Yes, although with the one example I've run across I can't say I'd use
> them the same way (uggg). Take a look at the LDAPv3 plugin in the
> DirectoryService package. In particular the CLDAPv3Plugin.cpp. Whoever
> wrote it constantly does stuff like this:
>
> tDirStatus CLDAPv3Plugin::CloseDirNode ( sCloseDirNode *inData )
> {
> tDirStatus siResult = eDSNoErr;
> sLDAPContextData *pContext = nil;
>
> try
> {
> pContext = gLDAPContextTable->GetObjectForRefNum( inData->fInNodeRef );
> if ( pContext == nil )
> throw( eDSBadContextData );
>
> // our last chance to clean up anything we missed for that node
> gLDAPContinueTable->RemovePointersForRefNum( inData->fInNodeRef );
> // clean up continues before we remove the first context itself..
>
> gLDAPContextTable->RemoveRefNum( inData->fInNodeRef );
> DSRelease( pContext );
> }
>
> catch ( tDirStatus err )
> {
> siResult = err;
> }
>
> return( siResult );
>
> } // CloseDirNode
>
> tDirStatus is an integer, in case you didn't figure that out.
_______________________________________________
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