Android Studio 未处理的异常警告 [英] Android Studio unhandled exception warnings
问题描述
当我输入诸如 JSONObject
解码或日期解析之类的某些行时,应用程序将无法编译,因为编译器会发出 UnhandledException
警告,我必须将调用包装在try/catch block
在应用程序编译之前.是否可以禁用它以便我不需要编写 try/catch 块
?
When I enter certain lines like JSONObject
decoding or date parsing, the app will not compile as the compiler gives an UnhandledException
warning and I have to wrap the call in a try/catch block
before the app will compile. Can this be disabled so that I don't need to write the try/catch block
?
推荐答案
正如我在评论中所说的,如果您使用的是 Android Studio 或 Eclipse 或任何其他 IDE,而使用显示错误的代码,您应该在何处换行你的代码带有 try/catch
块,你不能禁用它.您应该只添加块并更改代码,以便在程序执行的某个点抛出此异常时可以正确处理函数或类的其余部分.
As I said in the comment doesn't matter if you are using Android Studio or Eclipse or any other IDE, while using code which showing error where you should wrap your code with try / catch
block, you can't disable this. You should just add the block and change your code so you can handle the rest of your function or class properly if this exception is thrown in some point of program execution.
有关在 Java 中抛出和捕获异常的信息,您可以在此处阅读更多信息:
For throwing and catching exceptions in Java you can read more about here:
为了更好地解释哪些异常应该用 try/catch
块包装,哪些不用,这里有两个很好的例子:
and for better explanation of which exceptions should be wrapped with try/catch
block and which not, here are two good examples:
这篇关于Android Studio 未处理的异常警告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!