2013-02-13 121 views
0

我遇到了由我的老师给出的练习题之一的问题。我甚至不明白问题的要求,所以任何帮助,将不胜感激。需要帮助了解方法和例外[objectiveC]

“要练习方法和类,请用引发异常的方法编写一个类,为调用前一个方法的类编写另一个方法,捕获并处理该异常,使用main函数测试您的代码。

我明白的唯一事情就是用主函数对它进行测试。任何帮助将不胜感激,谢谢。

+0

我非常抱歉的方法,但我们并不对功课问题......最友好的网站。也许你可以阅读[NSException](https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Classes/NSException_Class/Reference/Reference.html)或[assertions](https:/ /developer.apple.com/library/mac/documentation/cocoa/reference/foundation/miscellaneous/foundation_functions/reference/reference.html#//apple_ref/c/macro/NSAssert)。 – CodaFi 2013-02-13 15:03:13

+0

你有教科书吗?讲座是否包含异常处理?你的教授有办公时间吗? – geoffspear 2013-02-13 15:03:43

+0

这比较适合聊天或论坛。请参阅这些文档:https://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/Exceptions/Tasks/HandlingExceptions.html – 2013-02-13 15:03:49

回答

1

你正在寻找的是一个包含try/catch语句

@try { 
    //do something 
} 
@catch (NSException *exception){ 
    //do something if the code in the try failed 

    //OR 
    @throw exception; //this will make the method called "above" this method handle the exception (eg a method calling another method, that fails, passes the exception back to the top level one) 
} 
+0

谢谢,这帮助我得到它:)。 – StackPWRequirmentsAreCrazy 2013-02-13 17:53:23