Re: [問題] 儲存資料到plist時的例外處理

看板MacDev作者 (←這人是超級笨蛋)時間11年前 (2013/06/15 01:51), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串2/2 (看更多)
※ 引述《neotek (尼澳鐵特)》之銘言: ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 1.34.110.106

06/14 16:05,
use try catch
06/14 16:05

06/14 16:49,
實作上我從來沒用過try-catch...
06/14 16:49

06/14 17:30,
你的case不需要用到 實做上會用到的機率很小
06/14 17:30

06/14 17:32,
會用到的情境大概是某段會crash但有某種理由要繼續下去
06/14 17:32

06/14 17:55,
try catch 掛的時候還是一樣會掛掉的
06/14 17:55

06/14 17:55,
我只有在連api時會用try-cache 而且只有用過一次...
06/14 17:55

06/14 17:58,
ios好像不會try cache中拋出exceptions 所以幾乎沒用
06/14 17:58

06/14 23:37,
會 只有APP要crash的時候
06/14 23:37

06/15 01:06,
應該是我碰到的case太少@@
06/15 01:06
http://goo.gl/ZV1yL [developer.apple.com] If you’re coming from other platforms and languages, you may be used to working with exceptions for the majority of error handling. When you’re writing code with Objective-C, exceptions are used solely for programmer errors, like out-of-bounds array access or invalid method arguments. These are the problems that you should find and fix during testing before you ship your app. Objective-C 的 exceptions 在本質上和 C++ 或 Java 或其他語言不一樣 寫 Objective-C 程式時的慣例是用 NSError 來表達失敗狀態 跳 exception 基本上就代表程式要炸了, 是最後一道防線 讀寫檔失敗這種可以補救的請不要隨便使用 像 NSData 的讀寫檔 methods 都有一個包含 error 回傳值的形式可以使用 還有另外一個考量點是 Objective-C 的 try-catch 相對很耗資源 (和 introspection 與 error-checking 比起來) -- "問おう、貴方が私のマスターか?" -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 114.32.81.146 ※ 編輯: uranusjr 來自: 114.32.81.146 (06/15 01:54)
文章代碼(AID): #1HkrWEdY (MacDev)
文章代碼(AID): #1HkrWEdY (MacDev)