AI-generated Key Takeaways
-
JSONExceptionsignals problems with the JSON API, such as malformed documents, invalid data types, or incorrect lookups. -
Though a checked exception, it's often wrapped in an unchecked exception (e.g.,
RuntimeException) for practical handling. -
It provides constructors to detail the error with a message, a cause, or both.
-
JSONExceptioninherits methods fromThrowablefor stack traces and error information.
Thrown to indicate a problem with the JSON API. Such problems include:
- Attempts to parse or construct malformed documents
- Use of null as a name
- Use of numeric types not available to JSON, such as
NaNsorinfinities. - Lookups using an out of range index or nonexistent name
- Type mismatches on lookups
Although this is a checked exception, it is rarely recoverable. Most callers should simply wrap this exception in an unchecked exception and rethrow:
public JSONArray toJSONObject() {
try {
JSONObject result = new JSONObject();
...
} catch (JSONException e) {
throw new RuntimeException(e);
}
}Public Constructor Summary
|
JSONException(String s)
|
|
|
JSONException(String message, Throwable cause)
|
|
|
JSONException(Throwable cause)
|
Inherited Method Summary
Public Constructors
public JSONException (String s)
Parameters
| s |
|---|
public JSONException (String message, Throwable cause)
Parameters
| message | |
|---|---|
| cause |
public JSONException (Throwable cause)
Parameters
| cause |
|---|