Class FormulaException
java.lang.Object
java.lang.Throwable
java.lang.Exception
com.iizix.prop.GUnitException
com.iizix.prop.gunit.FormulaException
- All Implemented Interfaces:
Serializable
Exception thrown when a unit formula cannot be compiled. In addition to the message, the exception carries the offset and the length of the offending span, expressed as character indices into the original, untouched source string that was handed to the
Lexer.The offsets are exact because nothing is ever substituted in the source before scanning: the previous implementation replaced every unit name with a single control character before it scanned, which collapsed e.g. "dlg" from three characters to one and shifted every position after the first unit by a varying amount.
Only the FIRST error is reported. There is deliberately no error recovery and no multiple-error reporting: it roughly doubles the parser complexity for what is a single-line formula field.
This class extends GUnitException so that existing callers that catch GUnitException keep working unchanged; only code that wants the caret position needs to know about this subclass.
- Author:
- Christopher Mindus
- See Also:
Constructor Summary
ConstructorsConstructorDescriptionFormulaException(String msg, int offset, int length) Creates the exception with a description and a source span.Method Summary
Methods inherited from class Throwable
addSuppressed, fillInStackTrace, getCause, getLocalizedMessage, getMessage, getStackTrace, getSuppressed, initCause, printStackTrace, printStackTrace, printStackTrace, setStackTrace
Constructor Details
FormulaException
Creates the exception with a description and a source span.- Parameters:
msg- The error message.offset- The zero based character offset into the ORIGINAL source string.length- The length in characters of the offending span, 0 at end-of-input.
Method Details
getOffset
public int getOffset()Gets the character offset of the error into the original source string.- Returns:
- The zero based offset.
getLength
public int getLength()Gets the length in characters of the offending span.- Returns:
- The length, 0 when the error is at end-of-input.
toString