Handling exceptions that occur during a method called through NSObject performs SelectorOnMainThread: withObject: waitUntilDone:

What happens to the exceptions that occurred during myMethod: if it is called through NSObject performSelectorOnMainThread:withObject:waitUntilDone: :?

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

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

I understand the semantics of this strange if waitUntilDone is NO .

+4
source share
1 answer

You cannot catch them. Cocoa can catch and log exceptions in the console, but it will not re-raise them in a thread called -perform. Instead, you can catch them in -myMethod: (or a shell that calls -myMethod :) and save them somewhere that your other thread can read them.

+5
source

Source: https://habr.com/ru/post/1277337/


All Articles