org.less4j
Class JSON.Error

java.lang.Object
  extended by java.lang.Throwable
      extended by java.lang.Exception
          extended by org.less4j.JSON.Error
All Implemented Interfaces:
java.io.Serializable
Direct Known Subclasses:
JSONR.Error
Enclosing class:
JSON

public static class JSON.Error
extends java.lang.Exception

A simple JSON exception throwed for any syntax error found by the interpreter.

Synopsis

There is just enough in a JSON.Error to identify the error
String string = "{\"test\": fail}";
try {
    Object value = (new JSON()).eval(string)
} catch (JSON.Error e) {
    System.out.println(e.jstr());
}

Copyright © 2006 Laurent A.V. Szyster

Version:
0.30
See Also:
Serialized Form

Field Summary
 int jsonIndex
          The position of the JSON syntax error, -1 by default.
 java.util.ArrayList jsonPath
          The path to the JSON error value, if any.
 
Constructor Summary
JSON.Error(java.lang.String message)
          Instanciate a JSON error with an error message.
JSON.Error(java.lang.String message, int index)
          Instanciate a JSON error with an error message and the index in the JSON string at which the error occured.
 
Method Summary
 java.lang.StringBuffer strb(java.lang.StringBuffer sb)
          Buffers the JSON representation of a JSON.Error.
 java.lang.String toJSONString()
          Represents a JSON error as a JSON array with three elements: the error message, the character index where the error occurred and the path in the object model.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Throwable
fillInStackTrace, getCause, getLocalizedMessage, getMessage, getStackTrace, initCause, printStackTrace, printStackTrace, printStackTrace, setStackTrace
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

jsonIndex

public int jsonIndex
The position of the JSON syntax error, -1 by default.


jsonPath

public java.util.ArrayList jsonPath
The path to the JSON error value, if any.

Constructor Detail

JSON.Error

public JSON.Error(java.lang.String message)
Instanciate a JSON error with an error message.

Parameters:
message - the error message

JSON.Error

public JSON.Error(java.lang.String message,
                  int index)
Instanciate a JSON error with an error message and the index in the JSON string at which the error occured.

Parameters:
message - the error message
index - position at which the error occured
Method Detail

strb

public java.lang.StringBuffer strb(java.lang.StringBuffer sb)
Buffers the JSON representation of a JSON.Error.

Synopsis

...

StringBuffer sb = new StringBuffer();
try {
    String model = (new JSON()).eval("{fail}");
} catch (JSONR.Error e) {
    e.jsonError(sb);
}
System.out.println(sb.toString());
...

Returns:
the updated StringBuffer

toJSONString

public java.lang.String toJSONString()

Represents a JSON error as a JSON array with three elements: the error message, the character index where the error occurred and the path in the object model.

Synopsis

...

["error message", 23, ["list", 2]]
...

Returns:
a JSON string

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Throwable