0

我对老师给出的一个练习题有疑问。我什至不明白这个问题在问什么,所以任何帮助将不胜感激。

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

我唯一了解的是使用主要功能对其进行测试。任何帮助将不胜感激,谢谢。

4

1 回答 1

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)
}
于 2013-02-13T15:06:21.043 回答