简体   繁体   中英

iPhone SDK Try Catch exception handling

I am writing a simple iPhone application and I am wondering if there is something equivalent to C#'s try{}-catch{}-finally{} exception handling.

I have come across a few references via google, but I am having trouble figuring out what the actual syntax is on the iPhone platform.

Does anyone know of a very basic example on how to do this?

Many thanks, Brett

The actual syntax on the iPhone platform/framework is the same as it is in obj-c because it is still obj-c with a set of classes. This kinda stuff is easily found in the online obj-c documentation provided by apple and any intro obj-c book. The Google-fu answer :

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

@try { 
    [cup fill]; 
} 
@catch (NSException *exception) { 
    NSLog(@"main: Caught %@: %@", [exception name], [exception reason]); 
} 
@finally { 
    [cup release]; 
} 

Now, if you are looking for how this code fits into an iPhone application then you can download a sample application and copy the syntactical structure.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM