1. 程式人生 > >OC語法--nil、 Nil、 NULL 、NSNul用法及OC異常處理

OC語法--nil、 Nil、 NULL 、NSNul用法及OC異常處理

Cup *cup = [[Cup alloc] init];

@try { 

[cup fill];

}

 @catch (NSException *exception) {

NSLog(@"main: Caught %@: %@", [exception name], [exception reason]);

@finally {

[cup release];

}

丟擲異常

為了擲出一個異常,我們必須例項化一個物件,當然這個物件要包含相關的資訊,比如異常的名字和為什麼要擲出他。

NSException *exception = [NSException exceptionWithName:@"HotTeaException" reason:@"The tea is too hot" userInfo:nil];

@throw exception;