How to catch exceptions in BlockCode (Objective-C)

Is there a way to catch exceptions in block code?

I got the following code:

void(^callback(int) = ^(int respond){ [self DoSomethingWithRespond:respond]; //this throws an exception }; -(void)DoSomethingWithRespond:(int)respond{ if(respond == 400){ NSException *exception = [NSException exceptionWithName:@"Failed" reason:logMessage userInfo:nil]; @throw exception } } 

Callback methods are called from another thread. If the answer is 400, the DoSomethingWithRespond method will throw an exception.

+6
source share
1 answer
  @try { <#statements#> } @catch (NSException *exception) { <#handler#> } @finally { <#statements#> } 
+4
source

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


All Articles