Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1878 | jmachado | 1 | package com.owlike.genson.stream; |
2 | |||
3 | /** |
||
4 | * JsonStreamException are thrown by ObjectWriter and ObjectReader implementations. They indicate |
||
5 | * that there was a syntax error or a state error (calling endObject when it should be endArray |
||
6 | * etc). |
||
7 | * |
||
8 | * @author eugen |
||
9 | */ |
||
10 | public final class JsonStreamException extends 1.5.0/docs/api/java/lang/RuntimeException.html">RuntimeException { |
||
11 | private static final long serialVersionUID = 8033784054415043293L; |
||
12 | |||
13 | private final int column; |
||
14 | private final int row; |
||
15 | |||
16 | public JsonStreamException(1.5.0/docs/api/java/lang/String.html">String message, 1.5.0/docs/api/java/lang/Throwable.html">Throwable cause) { |
||
17 | this(message, cause, -1, -1); |
||
18 | } |
||
19 | |||
20 | public JsonStreamException(1.5.0/docs/api/java/lang/String.html">String message) { |
||
21 | this(message, null); |
||
22 | } |
||
23 | |||
24 | public JsonStreamException(1.5.0/docs/api/java/lang/Throwable.html">Throwable cause) { |
||
25 | this(null, cause); |
||
26 | } |
||
27 | |||
28 | // package visibility, api users are not supposed to use it |
||
29 | JsonStreamException(1.5.0/docs/api/java/lang/String.html">String message, 1.5.0/docs/api/java/lang/Throwable.html">Throwable cause, int row, int col) { |
||
30 | super(message, cause); |
||
31 | this.column = col; |
||
32 | this.row = row; |
||
33 | } |
||
34 | |||
35 | public int getColumn() { |
||
36 | return column; |
||
37 | } |
||
38 | |||
39 | public int getRow() { |
||
40 | return row; |
||
41 | } |
||
42 | |||
43 | public static <T extends Exception> T niceTrace(T exception) { |
||
44 | final 1.5.0/docs/api/java/lang/StackTraceElement.html">StackTraceElement[] stackTrace = exception.getStackTrace(); |
||
45 | final 1.5.0/docs/api/java/lang/StackTraceElement.html">StackTraceElement[] newStackTrace = new 1.5.0/docs/api/java/lang/StackTraceElement.html">StackTraceElement[stackTrace.length - 1]; |
||
46 | |||
47 | 1.5.0/docs/api/java/lang/System.html">System.arraycopy(stackTrace, 1, newStackTrace, 0, stackTrace.length - 1); |
||
48 | exception.setStackTrace(newStackTrace); |
||
49 | return exception; |
||
50 | } |
||
51 | |||
52 | public JsonStreamException niceTrace() { |
||
53 | return niceTrace(this); |
||
54 | } |
||
55 | |||
56 | static class Builder { |
||
57 | private int col; |
||
58 | private int row; |
||
59 | private 1.5.0/docs/api/java/lang/String.html">String message; |
||
60 | private 1.5.0/docs/api/java/lang/Throwable.html">Throwable cause; |
||
61 | |||
62 | public JsonStreamException create() { |
||
63 | return new JsonStreamException(message, cause, row, col); |
||
64 | } |
||
65 | |||
66 | Builder locate(int row, int col) { |
||
67 | this.row = row; |
||
68 | this.col = col; |
||
69 | return this; |
||
70 | } |
||
71 | |||
72 | public Builder message(1.5.0/docs/api/java/lang/String.html">String message) { |
||
73 | this.message = message; |
||
74 | return this; |
||
75 | } |
||
76 | |||
77 | public Builder cause(1.5.0/docs/api/java/lang/Throwable.html">Throwable th) { |
||
78 | this.cause = th; |
||
79 | return this; |
||
80 | } |
||
81 | } |
||
82 | } |