简体   繁体   English

iPhone SDK Try Catch异常处理

[英]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. 我正在编写一个简单的iPhone应用程序,我想知道是否存在与C#的try {}-catch {}-finally {}异常处理等效的东西。

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. 我通过Google遇到了一些参考,但是我很难弄清楚iPhone平台上的实际语法是什么。

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. iPhone平台/框架上的实际语法与obj-c中的相同,因为它仍然是带有一组类的obj-c。 This kinda stuff is easily found in the online obj-c documentation provided by apple and any intro obj-c book. 这些东西很容易在apple和任何obj-c简介书籍提供的在线obj-c文档中找到。 The Google-fu answer : Google-fu 答案

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. 现在,如果您正在寻找该代码如何适合iPhone应用程序,则可以下载示例应用程序并复制语法结构。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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