Clover icon

Coverage Report

  1. Project Clover database Wed Nov 13 2024 16:21:17 GMT
  2. Package org.json.simple.parser

File ParseException.java

 

Coverage histogram

../../../../img/srcFileCovDistChart0.png
59% of files have more coverage

Code metrics

0
26
10
1
111
73
13
0.5
2.6
10
1.3

Classes

Class Line # Actions
ParseException 9 26 13
0.00%
 

Contributing tests

No tests hitting this source file were found.

Source view

1    package org.json.simple.parser;
2   
3    /**
4    * ParseException explains why and where the error occurs in source JSON text.
5    *
6    * @author FangYidong<fangyidong@yahoo.com.cn>
7    *
8    */
 
9    public class ParseException extends Exception
10    {
11    private static final long serialVersionUID = -7880698968187728547L;
12   
13    public static final int ERROR_UNEXPECTED_CHAR = 0;
14   
15    public static final int ERROR_UNEXPECTED_TOKEN = 1;
16   
17    public static final int ERROR_UNEXPECTED_EXCEPTION = 2;
18   
19    private int errorType;
20   
21    private Object unexpectedObject;
22   
23    private int position;
24   
 
25  0 toggle public ParseException(int errorType)
26    {
27  0 this(-1, errorType, null);
28    }
29   
 
30  0 toggle public ParseException(int errorType, Object unexpectedObject)
31    {
32  0 this(-1, errorType, unexpectedObject);
33    }
34   
 
35  0 toggle public ParseException(int position, int errorType,
36    Object unexpectedObject)
37    {
38  0 this.position = position;
39  0 this.errorType = errorType;
40  0 this.unexpectedObject = unexpectedObject;
41    }
42   
 
43  0 toggle public int getErrorType()
44    {
45  0 return errorType;
46    }
47   
 
48  0 toggle public void setErrorType(int errorType)
49    {
50  0 this.errorType = errorType;
51    }
52   
53    /**
54    * @see org.json.simple.parser.JSONParser#getPosition()
55    *
56    * @return The character position (starting with 0) of the input where the
57    * error occurs.
58    */
 
59  0 toggle public int getPosition()
60    {
61  0 return position;
62    }
63   
 
64  0 toggle public void setPosition(int position)
65    {
66  0 this.position = position;
67    }
68   
69    /**
70    * @see org.json.simple.parser.Yytoken
71    *
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
75    * java.lang.Exception
76    */
 
77  0 toggle public Object getUnexpectedObject()
78    {
79  0 return unexpectedObject;
80    }
81   
 
82  0 toggle public void setUnexpectedObject(Object unexpectedObject)
83    {
84  0 this.unexpectedObject = unexpectedObject;
85    }
86   
 
87  0 toggle public String getMessage()
88    {
89  0 StringBuffer sb = new StringBuffer();
90   
91  0 switch (errorType)
92    {
93  0 case ERROR_UNEXPECTED_CHAR:
94  0 sb.append("Unexpected character (").append(unexpectedObject)
95    .append(") at position ").append(position).append(".");
96  0 break;
97  0 case ERROR_UNEXPECTED_TOKEN:
98  0 sb.append("Unexpected token ").append(unexpectedObject)
99    .append(" at position ").append(position).append(".");
100  0 break;
101  0 case ERROR_UNEXPECTED_EXCEPTION:
102  0 sb.append("Unexpected exception at position ").append(position)
103    .append(": ").append(unexpectedObject);
104  0 break;
105  0 default:
106  0 sb.append("Unkown error at position ").append(position).append(".");
107  0 break;
108    }
109  0 return sb.toString();
110    }
111    }