Skip to content

Commit

Permalink
Merge pull request #236 from madsager/master
Browse files Browse the repository at this point in the history
Make nextString throw a JSONException instead of a NumberFormatExcept…
  • Loading branch information
stleary committed Jun 8, 2016
2 parents 612dafc + 16a86d7 commit eb569b5
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion JSONTokener.java
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,11 @@ public String nextString(char quote) throws JSONException {
sb.append('\r');
break;
case 'u':
sb.append((char)Integer.parseInt(this.next(4), 16));
try {
sb.append((char)Integer.parseInt(this.next(4), 16));
} catch (NumberFormatException e) {
throw this.syntaxError("Illegal escape.", e);
}
break;
case '"':
case '\'':
Expand Down Expand Up @@ -433,6 +437,16 @@ public JSONException syntaxError(String message) {
return new JSONException(message + this.toString());
}

/**
* Make a JSONException to signal a syntax error.
*
* @param message The error message.
* @param causedBy The throwable that caused the error.
* @return A JSONException object, suitable for throwing
*/
public JSONException syntaxError(String message, Throwable causedBy) {
return new JSONException(message + this.toString(), causedBy);
}

/**
* Make a printable string of this JSONTokener.
Expand Down

0 comments on commit eb569b5

Please sign in to comment.