public class JSONException extends java.lang.Exception implements TemplatizedMessage
Modifier and Type | Field and Description |
---|---|
static int |
MAXIMUM_PARAM_LENGTH |
java.lang.String[] |
params |
java.lang.String |
template |
Constructor and Description |
---|
JSONException(java.lang.String message)
Constructs a JSONException with an explanatory message.
|
JSONException(java.lang.String template,
java.lang.Object... params)
Construct the exception with a template by using variable parameters
Use a template like this:
|
JSONException(java.lang.String message,
java.lang.Throwable cause)
Constructs a JSONException with an explanatory message.
|
JSONException(java.lang.String template,
java.lang.Throwable cause,
java.lang.Object... params)
Construct the exception with a template by using variable parameters
with a pattern like this:
|
Modifier and Type | Method and Description |
---|---|
static boolean |
containsMessage(java.lang.Throwable t,
java.lang.String fragment)
When an exception is caught, you will want to test whether the exception, or any of
the causing exceptions contains a particular string fragment.
|
static java.lang.Exception |
convertJSONToException(JSONObject ex)
Given a JSON representation of an exception, this re-constructs the Exception
chain (linked cause exceptions) and returns the Exception object.
|
static JSONObject |
convertToJSON(java.lang.Throwable e,
java.lang.String context)
In any kind of JSON protocol, you need to return an exception back to the caller.
|
static java.lang.String |
formatString(java.lang.String template,
java.lang.String[] params) |
java.lang.String |
getFormattedMessage() |
static java.lang.String |
getFullMessage(java.lang.Throwable e)
Walks through a chain of exception objects, from the first, to each
"cause" in turn, creating a single combined string message from all
the exception objects in the chain, with newline characters between
each exception message.
|
java.lang.String[] |
getParameters() |
java.lang.String |
getStdTemplate()
Get a message template with the form of
"Problem {0} found in {1}"
Parameters are zero based
Parameters are in curly braces
|
static java.lang.String |
getTraceExceptionFormat(JSONObject errOb)
If you have already converted to a JSONOBject, you can use this method to
get a standard trace of that object to the output writer.
|
static int |
safeConvertInt(java.lang.String val) |
static java.lang.String[] |
stringifyParams(java.lang.Object[] input) |
java.lang.String |
substituteParams() |
static void |
traceConvertedException(java.io.PrintStream out,
JSONObject errOb)
If you have already converted to a JSONOBject, you can use this method to
get a standard trace of that object to the output writer.
|
static void |
traceConvertedException(java.io.Writer w,
JSONObject errOb) |
static JSONObject |
traceException(java.io.PrintStream out,
java.lang.Throwable e,
java.lang.String context)
A standardized way to trace a given exception to the system out.
|
static JSONObject |
traceException(java.lang.Throwable e,
java.lang.String context)
A standardized way to trace a given exception to the system out.
|
static JSONObject |
traceException(java.io.Writer w,
java.lang.Throwable e,
java.lang.String context)
A standardized way to trace a given exception to the system out.
|
public java.lang.String template
public java.lang.String[] params
public static int MAXIMUM_PARAM_LENGTH
public JSONException(java.lang.String message)
message
- Detail about the reason for the exception.public JSONException(java.lang.String message, java.lang.Throwable cause)
message
- Detail about the reason for the exception.public JSONException(java.lang.String template, java.lang.Object... params)
JSONException("Error when contemplating {0} in context of {1}", value0, value1)Tokens are braces with a single digit numeral between them. The message will ultimately include the main string template with the values substituted, however this gives the option to translate the template before substitution and get a translated message. Parameters can be any object, but they are immediately conferted to a string using toString so if you want different formatting convert to a string before passing the value in. Parameters are truncated to MAXIMUM_PARAM_LENGTH. The static value MAXIMUM_PARAM_LENGTH can be modified by containing program.
public JSONException(java.lang.String template, java.lang.Throwable cause, java.lang.Object... params)
JSONException("Error when contemplating {0} in context of {1}", ex, value0, value1)See JSONException constructor without Throwable for more details.
public static java.lang.String[] stringifyParams(java.lang.Object[] input)
public static java.lang.String formatString(java.lang.String template, java.lang.String[] params)
public static int safeConvertInt(java.lang.String val)
public static java.lang.String getFullMessage(java.lang.Throwable e)
public static boolean containsMessage(java.lang.Throwable t, java.lang.String fragment)
public java.lang.String substituteParams()
public static JSONObject convertToJSON(java.lang.Throwable e, java.lang.String context) throws java.lang.Exception
context
- allows you to include some context about the operation that was being performed
when the exception occurred.java.lang.Exception
public static JSONObject traceException(java.lang.Throwable e, java.lang.String context)
public static JSONObject traceException(java.io.PrintStream out, java.lang.Throwable e, java.lang.String context)
public static JSONObject traceException(java.io.Writer w, java.lang.Throwable e, java.lang.String context)
public static void traceConvertedException(java.io.PrintStream out, JSONObject errOb)
public static void traceConvertedException(java.io.Writer w, JSONObject errOb)
public static java.lang.String getTraceExceptionFormat(JSONObject errOb)
public static java.lang.Exception convertJSONToException(JSONObject ex)
public java.lang.String getStdTemplate()
TemplatizedMessage
getStdTemplate
in interface TemplatizedMessage
public java.lang.String[] getParameters()
getParameters
in interface TemplatizedMessage
public java.lang.String getFormattedMessage()
getFormattedMessage
in interface TemplatizedMessage