Why/how is org.json.JSONException unchecked?

你。 提交于 2020-05-31 08:48:58

问题


Reading How to identify checked and unchecked exceptions in java? makes me wonder:

Why is org.json.JSONException unchecked according to maven and eclipse? (no compilation error when not handled)

Both are extending java.lang.Exception according to the javadoc and the source code...


org.JSON.JSONArray produces no error without try/catch: org.JSON.JSONArray produces no error without trycatch


For comparison, here is a checked exception example:

atg.taglib.json.util.JSONArray produces an error without try/catch: atg.taglib.json.util.JSONArray produces an error without trycatch

atg.taglib.json.util.JSONArray produces no error with try/catch: atg.taglib.json.util.JSONArray produces no error with trycatch


回答1:


You have an old version of the org.json library. I guess they also haven't updated their doc in a while. Since version 20131018, JSONException extends RuntimeException and is therefore an unchecked exception.

You can see it in the source code, here.



来源:https://stackoverflow.com/questions/29170315/why-how-is-org-json-jsonexception-unchecked

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!