java.lang.Object
java.lang.Throwable
java.lang.Exception
java.lang.RuntimeException
java.lang.IllegalArgumentException
org.bzdev.util.ObjectParser.Exception
- All Implemented Interfaces:
Serializable
- Enclosing interface:
- ObjectParser<T>
Exception class for ObjectParser errors.
This class provides access methods to recover the string that
was being parsed and the offset into the string that is associated
with the error.
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionConstructor.Constructor with a file name.Constructor with a cause.Constructor with a file name and cause. -
Method Summary
Modifier and TypeMethodDescriptionGet the file name.getInput()
Get the input string for which the error occurred.Get the message for this exception.getMessage
(String prefix, boolean verbose, boolean showLocation) Get the error message with an explicitly provided prefix.int
Get the offset into the input string for the location at which an error occurred.Get the message as it was provided to this exception's constructor.void
Set the text that should precede each line of an error message.void
showLocation
(boolean mode) Indicate if a line showing the location of an error message should be added.Methods inherited from class java.lang.Throwable
addSuppressed, fillInStackTrace, getCause, getLocalizedMessage, getStackTrace, getSuppressed, initCause, printStackTrace, printStackTrace, printStackTrace, setStackTrace, toString
-
Constructor Details
-
Exception
Constructor.- Parameters:
msg
- a message describing this exceptioninput
- the input stringoffset
- an offset into the string indicating where an error occurred; -1 if there is no specific offset
-
Exception
Constructor with a file name.- Parameters:
msg
- a message describing this exceptionfilename
- the name of the inputinput
- the input stringoffset
- an offset into the string indicating where an error occurred; -1 if there is no specific offset
-
Exception
Constructor with a cause.- Parameters:
msg
- a message describing this exceptioncause
- the Trowable that caused this exceptioninput
- the input stringoffset
- an offset into the string indicating where an error occurred; -1 if there is no specific offset
-
Exception
Constructor with a file name and cause.- Parameters:
msg
- a message describing this exceptioncause
- the Trowable that caused this exceptionfilename
- the name of the inputinput
- the input stringoffset
- an offset into the string indicating where an error occurred; -1 if there is no specific offset
-
-
Method Details
-
getInput
Get the input string for which the error occurred.- Returns:
- the string
-
getFileName
Get the file name.- Returns:
- the file name; null if there is none
-
getOffset
public int getOffset()Get the offset into the input string for the location at which an error occurred.- Returns:
- the offset; -1 if none is known
-
getPlainMessage
Get the message as it was provided to this exception's constructor.- Returns:
- the message.
-
setPrefix
Set the text that should precede each line of an error message. The method assumes that the message used to create this exception is on a single line.- Parameters:
prefix
- the prefix
-
showLocation
public void showLocation(boolean mode) Indicate if a line showing the location of an error message should be added.- Parameters:
mode
- true if a location should be added; false otherwise
-
getMessage
Get the message for this exception. The message will be annotated by adding a prefix, which can be set by callingsetPrefix(String)
, and appending lines, each starting with the prefix, that contain a line from an input file or string, and a pointer indicating where in the line the error was detected. The first line will include a filename (if provided) and a line number.- Overrides:
getMessage
in classThrowable
- Returns:
- the annotated message
-
getMessage
Get the error message with an explicitly provided prefix. The prefix will start each line of the message.- Parameters:
prefix
- the prefixverbose
- true if fully-qualified class names should be shown; false for just the final component of the class nameshowLocation
- true to show the location for an error message; false otherwise- Returns:
- the error message
-