Re: [問題] 儲存資料到plist時的例外處理
※ 引述《neotek (尼澳鐵特)》之銘言:
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 1.34.110.106
推
06/14 16:05,
06/14 16:05
推
06/14 16:49,
06/14 16:49
→
06/14 17:30,
06/14 17:30
→
06/14 17:32,
06/14 17:32
→
06/14 17:55,
06/14 17:55
→
06/14 17:55,
06/14 17:55
→
06/14 17:58,
06/14 17:58
→
06/14 23:37,
06/14 23:37
→
06/15 01:06,
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)
討論串 (同標題文章)
本文引述了以下文章的的內容:
完整討論串 (本文為第 2 之 2 篇):