1 /* 2 * hunt-time: A time library for D programming language. 3 * 4 * Copyright (C) 2015-2018 HuntLabs 5 * 6 * Website: https://www.huntlabs.net/ 7 * 8 * Licensed under the Apache-2.0 License. 9 * 10 */ 11 12 module hunt.time.format.DateTimeParseException; 13 14 import hunt.time.Exceptions; 15 16 /** 17 * An exception thrown when an error occurs during parsing. 18 * !(p) 19 * This exception includes the text being parsed and the error index. 20 * 21 * @implSpec 22 * This class is intended for use _in a single thread. 23 * 24 * @since 1.8 25 */ 26 public class DateTimeParseException : DateTimeException { 27 28 /** 29 * Serialization version. 30 */ 31 private static const long serialVersionUID = 4304633501674722597L; 32 33 /** 34 * The text that was being parsed. 35 */ 36 private const string parsedString; 37 /** 38 * The error index _in the text. 39 */ 40 private const int errorIndex; 41 42 /** 43 * Constructs a new exception with the specified message. 44 * 45 * @param message the message to use for this exception, may be null 46 * @param parsedData the parsed text, should not be null 47 * @param errorIndex the index _in the parsed string that was invalid, should be a valid index 48 */ 49 public this(string message, string parsedData, int errorIndex) { 50 super(message); 51 this.parsedString = parsedData; 52 this.errorIndex = errorIndex; 53 } 54 55 /** 56 * Constructs a new exception with the specified message and cause. 57 * 58 * @param message the message to use for this exception, may be null 59 * @param parsedData the parsed text, should not be null 60 * @param errorIndex the index _in the parsed string that was invalid, should be a valid index 61 * @param cause the cause exception, may be null 62 */ 63 public this(string message, string parsedData, int errorIndex, Throwable cause) { 64 super(message, cause); 65 this.parsedString = parsedData; 66 this.errorIndex = errorIndex; 67 } 68 69 //----------------------------------------------------------------------- 70 /** 71 * Returns the string that was being parsed. 72 * 73 * @return the string that was being parsed, should not be null. 74 */ 75 public string getParsedString() { 76 return parsedString; 77 } 78 79 /** 80 * Returns the index where the error was found. 81 * 82 * @return the index _in the parsed string that was invalid, should be a valid index 83 */ 84 public int getErrorIndex() { 85 return errorIndex; 86 } 87 88 }