3

So I've read a lot about catching exceptions. Let's talk about this and iOS together. I've used it with Google Analytics to submit information about the crash and using that to fix bugs.

But this raises a question. Can catching these exceptions help prevent apps from crashing. Can you theoretically prevent that bit of code from crashing the app and keep the app open. Now I get the fact that it would probably be impossible to do if there was no memory to be used but it would still be nice to know about.

Sorry if this sounds like a stupid questions and I really should read more about it and do some more research. Any information would be helpful.

I do have a fairly decent knowledge of iOS obj-c for my age and am willing to look into what you have to say.

Thanks!

4

1 回答 1

2

永远不应该捕获 iOS 上的异常;它们是致命的,这是有原因的。与大多数具有丰富的异常层次结构和多种抛出/捕获异常的方式以使程序整体受益的语言不同,Cocoa-Touch 代码是围绕所有异常都是致命的原则构建的。认为您可以捕获通过 Apple 提供的代码的任何帧抛出的异常并让您的过程不受阻碍地继续进行是错误的。为了记录的目的而捕获并重新抛出异常是一个更严重的错误。

Cocoa-Touch 抛出的异常表示程序逻辑中的严重错误,或对象中未定义和无法解决的状态。不能忽略它们,或者在捕获它们之后将它们记录下来。为了真正保证您的过程保持稳定,必须首先修复它们并防止它们被抛出。

于 2013-08-31T05:46:47.977 回答