6

ブロックコード内で例外をキャッチする適切な方法はありますか?

次のコードを取得しました。

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
   }
}

コールバック メソッドは別のスレッドから呼び出されます。応答が 400 に等しい場合、DoSomethingWithRespondメソッドは例外をスローします。

4

1 に答える 1

4
    @try {
        <#statements#>
    }
    @catch (NSException *exception) {
        <#handler#>
    }
    @finally {
        <#statements#>
    }
于 2012-06-04T12:31:41.017 に答える