Re: My try/catch block isn't catching exceptions on 10.6
Re: My try/catch block isn't catching exceptions on 10.6
- Subject: Re: My try/catch block isn't catching exceptions on 10.6
- From: Greg Parker <email@hidden>
- Date: Sat, 28 Nov 2009 01:25:38 -0800
On Nov 27, 2009, at 1:14 AM, Matt Gough wrote:
The equivalent in Obj-c would be :
@try
{
...
}
@catch( NSException* e)
{
// deal with NSException
}
@catch(id ue)
{
// deal with any other sort of exception
}
There's also `@catch (...)` in Objective-C.
On iPhone and 64-bit Mac, `@catch (...)` catches all C++ exceptions as
well as any otherwise-unhandled Objective-C exceptions. You can
rethrow your (possibly-C++) exception with `@throw;`.
On 32-bit Mac, `@catch (...)` and `@catch (id)` are the same, because C
++ exceptions are completely ignored.
Here's a fun idiom for handling both C++ and Objective-C exceptions in
the same place (on iPhone and 64-bit Mac).
@try {
// do stuff
} @catch (NSException *e) {
// NSException
} @catch (id e) {
// Other Objective-C exception
} @catch (...) {
// Non-ObjC exception
// Decode it by rethrowing it inside a C++ try/catch.
try {
@throw;
} catch (std::bad_cast& e) {
// C++ failed dynamic cast to reference type
} catch (...) {
// Other C++ exception
// or non-ObjC non-C++ foreign exception
}
}
--
Greg Parker email@hidden Runtime Wrangler
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden