001/* 002 * Copyright (c) 2007-2013, Stephen Colebourne & Michael Nascimento Santos 003 * 004 * All rights reserved. 005 * 006 * Redistribution and use in source and binary forms, with or without 007 * modification, are permitted provided that the following conditions are met: 008 * 009 * * Redistributions of source code must retain the above copyright notice, 010 * this list of conditions and the following disclaimer. 011 * 012 * * Redistributions in binary form must reproduce the above copyright notice, 013 * this list of conditions and the following disclaimer in the documentation 014 * and/or other materials provided with the distribution. 015 * 016 * * Neither the name of JSR-310 nor the names of its contributors 017 * may be used to endorse or promote products derived from this software 018 * without specific prior written permission. 019 * 020 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 021 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 022 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 023 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 024 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 025 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 026 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 027 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 028 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 029 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 030 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 031 */ 032package org.threeten.bp.format; 033 034import org.threeten.bp.DateTimeException; 035 036/** 037 * An exception thrown when an error occurs during parsing. 038 * <p> 039 * This exception includes the text being parsed and the error index. 040 * 041 * <h3>Specification for implementors</h3> 042 * This class is intended for use in a single thread. 043 */ 044public class DateTimeParseException extends DateTimeException { 045 046 /** 047 * Serialization version. 048 */ 049 private static final long serialVersionUID = 4304633501674722597L; 050 051 /** 052 * The text that was being parsed. 053 */ 054 private final String parsedString; 055 /** 056 * The error index in the text. 057 */ 058 private final int errorIndex; 059 060 /** 061 * Constructs a new exception with the specified message. 062 * 063 * @param message the message to use for this exception, may be null 064 * @param parsedData the parsed text, should not be null 065 * @param errorIndex the index in the parsed string that was invalid, should be a valid index 066 */ 067 public DateTimeParseException(String message, CharSequence parsedData, int errorIndex) { 068 super(message); 069 this.parsedString = parsedData.toString(); 070 this.errorIndex = errorIndex; 071 } 072 073 /** 074 * Constructs a new exception with the specified message and cause. 075 * 076 * @param message the message to use for this exception, may be null 077 * @param parsedData the parsed text, should not be null 078 * @param errorIndex the index in the parsed string that was invalid, should be a valid index 079 * @param cause the cause exception, may be null 080 */ 081 public DateTimeParseException(String message, CharSequence parsedData, int errorIndex, Throwable cause) { 082 super(message, cause); 083 this.parsedString = parsedData.toString(); 084 this.errorIndex = errorIndex; 085 } 086 087 //----------------------------------------------------------------------- 088 /** 089 * Returns the string that was being parsed. 090 * 091 * @return the string that was being parsed, should not be null. 092 */ 093 public String getParsedString() { 094 return parsedString; 095 } 096 097 /** 098 * Returns the index where the error was found. 099 * 100 * @return the index in the parsed string that was invalid, should be a valid index 101 */ 102 public int getErrorIndex() { 103 return errorIndex; 104 } 105 106}