How to catch exceptions within BlockCode (Objective C)

objective-c, objective-c-blocks

Solution

    @try {
        <#statements#>
    }
    @catch (NSException *exception) {
        <#handler#>
    }
    @finally {
        <#statements#>
    }

Problem

Is there a proper way to catch exceptions within 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 } } ``` The callback methods gets called from another thread. If the respond is equal to 400 the `DoSomethingWithRespond` method will throw an exception.

Original source