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 com开发者_运维知识库e 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.
精彩评论