views:

302

answers:

1

What happens to exceptions raised while in myMethod: if it is invoked via NSObject's performSelectorOnMainThread:withObject:waitUntilDone:?

In particular, can I catch them in the scope of the call to performSelectorOnMainThread like this...

@try {
    [self performSelectorOnMainThread:@selector(myMethod) withObject:nil waitUntilDone:YES];
} @catch(NSException *e) {
    //deal with exception raised in myMethod here??
}

I realize that the semantics of this are weird if waitUntilDone is NO.

+5  A: 

You won't be able to catch them like that. Cocoa may catch and log the exceptions to the console, but it won't re-raise them in the thread that called -perform. Instead, you could catch them in -myMethod: (or a wrapper that calls -myMethod:) and have it store them somewhere that your other thread can read them.

Michael Tsai