作者uranusjr (←这人是超级笨蛋)
看板MacDev
标题Re: [问题] 储存资料到plist时的例外处理
时间Sat Jun 15 01:51:07 2013
※ 引述《neotek (尼澳铁特)》之铭言:
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 1.34.110.106
1F:推 sohumi:use try catch 06/14 16:05
2F:推 tom19830924:实作上我从来没用过try-catch... 06/14 16:49
3F:→ charlesdc:你的case不需要用到 实做上会用到的机率很小 06/14 17:30
4F:→ charlesdc:会用到的情境大概是某段会crash但有某种理由要继续下去 06/14 17:32
5F:→ nobody1:try catch 挂的时候还是一样会挂掉的 06/14 17:55
6F:→ yuanruo:我只有在连api时会用try-cache 而且只有用过一次... 06/14 17:55
7F:→ yuanruo:ios好像不会try cache中抛出exceptions 所以几乎没用 06/14 17:58
8F:→ charlesdc:会 只有APP要crash的时候 06/14 23:37
9F:→ charlesdc:应该是我碰到的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)