2013-02-13 33 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