Package org.antlr.v4.runtime
Class RecognitionException
java.lang.Object
java.lang.Throwable
java.lang.Exception
java.lang.RuntimeException
org.antlr.v4.runtime.RecognitionException
- All Implemented Interfaces:
Serializable
- Direct Known Subclasses:
FailedPredicateException,InputMismatchException,LexerNoViableAltException,NoViableAltException
The root of the ANTLR exception hierarchy. In general, ANTLR tracks just
3 kinds of errors: prediction errors, failed predicate errors, and
mismatched input errors. In each case, the parser knows where it is
in the input, where it is in the ATN, the rule invocation stack,
and what kind of problem occurred.
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final RuleContextprivate final IntStreamprivate intprivate TokenThe currentTokenwhen an error occurred.private final Recognizer<?,?> TheRecognizerwhere this exception originated.private static final long -
Constructor Summary
ConstructorsConstructorDescriptionRecognitionException(String message, Recognizer<Token, ?> recognizer, IntStream input, ParserRuleContext ctx) RecognitionException(Lexer lexer, CharStream input) RecognitionException(Recognizer<Token, ?> recognizer, IntStream input, ParserRuleContext ctx) -
Method Summary
Modifier and TypeMethodDescriptionGets theRuleContextat the time this exception was thrown.Gets the set of input symbols which could potentially follow the previously matched symbol at the time this exception was thrown.Gets the input stream which is the symbol source for the recognizer where this exception was thrown.intGet the ATN state number the parser was in at the time the error occurred.<T> TgetOffendingToken(Recognizer<T, ?> recognizer) Recognizer<?,?> Gets theRecognizerwhere this exception occurred.protected final voidsetOffendingState(int offendingState) protected final <Symbol extends Token>
voidsetOffendingToken(Recognizer<Symbol, ?> recognizer, Symbol offendingToken) Methods inherited from class java.lang.Throwable
addSuppressed, fillInStackTrace, getCause, getLocalizedMessage, getMessage, getStackTrace, getSuppressed, initCause, printStackTrace, printStackTrace, printStackTrace, setStackTrace, toString
-
Field Details
-
serialVersionUID
private static final long serialVersionUID- See Also:
-
recognizer
TheRecognizerwhere this exception originated. -
ctx
-
input
-
offendingToken
-
offendingState
private int offendingState
-
-
Constructor Details
-
RecognitionException
-
RecognitionException
public RecognitionException(@Nullable Recognizer<Token, ?> recognizer, @Nullable IntStream input, @Nullable ParserRuleContext ctx) -
RecognitionException
public RecognitionException(String message, @Nullable Recognizer<Token, ?> recognizer, @Nullable IntStream input, @Nullable ParserRuleContext ctx)
-
-
Method Details
-
getOffendingState
public int getOffendingState()Get the ATN state number the parser was in at the time the error occurred. ForNoViableAltExceptionandLexerNoViableAltExceptionexceptions, this is theDecisionStatenumber. For others, it is the state whose outgoing edge we couldn't match.If the state number is not known, this method returns -1.
-
setOffendingState
protected final void setOffendingState(int offendingState) -
getExpectedTokens
Gets the set of input symbols which could potentially follow the previously matched symbol at the time this exception was thrown.If the set of expected tokens is not known and could not be computed, this method returns
null.- Returns:
- The set of token types that could potentially follow the current
state in the ATN, or
nullif the information is not available.
-
getContext
Gets theRuleContextat the time this exception was thrown.If the context is not available, this method returns
null.- Returns:
- The
RuleContextat the time this exception was thrown. If the context is not available, this method returnsnull.
-
getInputStream
Gets the input stream which is the symbol source for the recognizer where this exception was thrown.If the input stream is not available, this method returns
null.- Returns:
- The input stream which is the symbol source for the recognizer
where this exception was thrown, or
nullif the stream is not available.
-
getOffendingToken
-
setOffendingToken
protected final <Symbol extends Token> void setOffendingToken(Recognizer<Symbol, ?> recognizer, @Nullable Symbol offendingToken) -
getRecognizer
Gets theRecognizerwhere this exception occurred.If the recognizer is not available, this method returns
null.- Returns:
- The recognizer where this exception occurred, or
nullif the recognizer is not available.
-
getOffendingToken
-