1 package org.json.simple.parser;
4 * ParseException explains why and where the error occurs in source JSON text.
6 * @author FangYidong<fangyidong@yahoo.com.cn>
9 public class ParseException extends Exception
11 private static final long serialVersionUID = -7880698968187728547L;
13 public static final int ERROR_UNEXPECTED_CHAR = 0;
15 public static final int ERROR_UNEXPECTED_TOKEN = 1;
17 public static final int ERROR_UNEXPECTED_EXCEPTION = 2;
19 private int errorType;
21 private Object unexpectedObject;
25 public ParseException(int errorType)
27 this(-1, errorType, null);
30 public ParseException(int errorType, Object unexpectedObject)
32 this(-1, errorType, unexpectedObject);
35 public ParseException(int position, int errorType,
36 Object unexpectedObject)
38 this.position = position;
39 this.errorType = errorType;
40 this.unexpectedObject = unexpectedObject;
43 public int getErrorType()
48 public void setErrorType(int errorType)
50 this.errorType = errorType;
54 * @see org.json.simple.parser.JSONParser#getPosition()
56 * @return The character position (starting with 0) of the input where the
59 public int getPosition()
64 public void setPosition(int position)
66 this.position = position;
70 * @see org.json.simple.parser.Yytoken
72 * @return One of the following base on the value of errorType:
73 * ERROR_UNEXPECTED_CHAR java.lang.Character ERROR_UNEXPECTED_TOKEN
74 * org.json.simple.parser.Yytoken ERROR_UNEXPECTED_EXCEPTION
77 public Object getUnexpectedObject()
79 return unexpectedObject;
82 public void setUnexpectedObject(Object unexpectedObject)
84 this.unexpectedObject = unexpectedObject;
87 public String getMessage()
89 StringBuffer sb = new StringBuffer();
93 case ERROR_UNEXPECTED_CHAR:
94 sb.append("Unexpected character (").append(unexpectedObject)
95 .append(") at position ").append(position).append(".");
97 case ERROR_UNEXPECTED_TOKEN:
98 sb.append("Unexpected token ").append(unexpectedObject)
99 .append(" at position ").append(position).append(".");
101 case ERROR_UNEXPECTED_EXCEPTION:
102 sb.append("Unexpected exception at position ").append(position)
103 .append(": ").append(unexpectedObject);
106 sb.append("Unkown error at position ").append(position).append(".");
109 return sb.toString();