1 /* 2 * #%L 3 * JsonParseException.java - mongodb-async-driver - Allanbank Consulting, Inc. 4 * %% 5 * Copyright (C) 2011 - 2014 Allanbank Consulting, Inc. 6 * %% 7 * Licensed under the Apache License, Version 2.0 (the "License"); 8 * you may not use this file except in compliance with the License. 9 * You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, software 14 * distributed under the License is distributed on an "AS IS" BASIS, 15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 * See the License for the specific language governing permissions and 17 * limitations under the License. 18 * #L% 19 */ 20 package com.allanbank.mongodb.error; 21 22 /** 23 * JsonParseException provides an exception to throw when parsing a JSON 24 * document fails. 25 * 26 * @api.yes This exception is part of the driver's API. Public and protected 27 * members will be deprecated for at least 1 non-bugfix release 28 * (version numbers are <major>.<minor>.<bugfix>) 29 * before being removed or modified. 30 * @copyright 2012-2013, Allanbank Consulting, Inc., All Rights Reserved 31 */ 32 public class JsonParseException extends JsonException { 33 34 /** Serialization version of the class. */ 35 private static final long serialVersionUID = 8248891467581639959L; 36 37 /** The approximate column where the parse failed. */ 38 private final int myColumn; 39 40 /** The approximate line where the parse failed. */ 41 private final int myLine; 42 43 /** 44 * Creates a new JsonParseException. 45 */ 46 public JsonParseException() { 47 super(); 48 myLine = -1; 49 myColumn = -1; 50 } 51 52 /** 53 * Creates a new JsonParseException. 54 * 55 * @param message 56 * Reason for the exception. 57 */ 58 public JsonParseException(final String message) { 59 super(message); 60 myLine = -1; 61 myColumn = -1; 62 } 63 64 /** 65 * Creates a new JsonParseException. 66 * 67 * @param message 68 * Reason for the exception. 69 * @param line 70 * The approximate line where the parse failed. 71 * @param column 72 * The approximate column where the parse failed. 73 */ 74 public JsonParseException(final String message, final int line, 75 final int column) { 76 super(message); 77 myLine = line; 78 myColumn = column; 79 } 80 81 /** 82 * Creates a new JsonParseException. 83 * 84 * @param message 85 * Reason for the exception. 86 * @param cause 87 * The exception causing the MongoDbException. 88 */ 89 public JsonParseException(final String message, final Throwable cause) { 90 super(message, cause); 91 myLine = -1; 92 myColumn = -1; 93 } 94 95 /** 96 * Creates a new JsonParseException. 97 * 98 * @param message 99 * Reason for the exception. 100 * @param cause 101 * The exception causing the MongoDbException. 102 * @param line 103 * The approximate line where the parse failed. 104 * @param column 105 * The approximate column where the parse failed. 106 */ 107 public JsonParseException(final String message, final Throwable cause, 108 final int line, final int column) { 109 super(message, cause); 110 myLine = line; 111 myColumn = column; 112 } 113 114 /** 115 * Creates a new JsonParseException. 116 * 117 * @param cause 118 * The exception causing the MongoDbException. 119 */ 120 public JsonParseException(final Throwable cause) { 121 super(cause); 122 myLine = -1; 123 myColumn = -1; 124 } 125 126 /** 127 * Returns the approximate column where the parse failed. Returns a negative 128 * value if the column is not known. 129 * 130 * @return The approximate column where the parse failed. 131 */ 132 public int getColumn() { 133 return myColumn; 134 } 135 136 /** 137 * Returns the approximate line where the parse failed. Returns a negative 138 * value if the line is not known. 139 * 140 * @return The approximate line where the parse failed. 141 */ 142 public int getLine() { 143 return myLine; 144 } 145 }