Top Description Fields Constructors Methods
org.antlr.v4.runtime

public Class RecognitionException

extends RuntimeException
Class Inheritance
Known Direct Subclasses
org.antlr.v4.runtime.FailedPredicateException, org.antlr.v4.runtime.InputMismatchException, org.antlr.v4.runtime.LexerNoViableAltException, org.antlr.v4.runtime.NoViableAltException
Imports
org.antlr.v4.runtime.atn.DecisionState, org.antlr.v4.runtime.misc.IntervalSet, .Nullable

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.

Field Summary

Modifier and TypeField and Description
private final RuleContext
private final IntStream
private int
private Token
offendingToken

The current Token when an error occurred.

private final Recognizer<?, ?>
recognizer

The Recognizer where this exception originated.

private static final long

Constructor Summary

AccessConstructor and Description
public
public
public

Method Summary

Modifier and TypeMethod and Description
public RuleContext

Returns:

The RuleContext at the time this exception was thrown. If the context is not available, this method returns null.
getContext
()

Gets the RuleContext at the time this exception was thrown.

public IntervalSet

Returns:

The set of token types that could potentially follow the current state in the ATN, or null if the information is not available.
getExpectedTokens
()

Gets the set of input symbols which could potentially follow the previously matched symbol at the time this exception was thrown.

public IntStream

Returns:

The input stream which is the symbol source for the recognizer where this exception was thrown, or null if the stream is not available.
getInputStream
()

Gets the input stream which is the symbol source for the recognizer where this exception was thrown.

public int
getOffendingState()

Get the ATN state number the parser was in at the time the error occurred.

public Token
public <T> T
getOffendingToken(Recognizer<T, ?> recognizer)

public Recognizer<?, ?>

Returns:

The recognizer where this exception occurred, or null if the recognizer is not available.
getRecognizer
()

Gets the Recognizer where this exception occurred.

protected final void
setOffendingState(int offendingState)

protected final <Symbol extends Token> void
setOffendingToken(Recognizer<Symbol, ?> recognizer, Symbol offendingToken)

Field Detail

ctxback to summary
private final RuleContext ctx
Annotations
@Nullable
inputback to summary
private final IntStream input
Annotations
@Nullable
offendingStateback to summary
private int offendingState
offendingTokenback to summary
private Token offendingToken

The current Token when an error occurred. Since not all streams support accessing symbols by index, we have to track the Token instance itself.

recognizerback to summary
private final Recognizer<?, ?> recognizer

The Recognizer where this exception originated.

Annotations
@Nullable
serialVersionUIDback to summary
private static final long serialVersionUID

Hides java.lang.RuntimeException.serialVersionUID.

Constructor Detail

RecognitionExceptionback to summary
public RecognitionException(Lexer lexer, CharStream input)
RecognitionExceptionback to summary
public RecognitionException(Recognizer<Token, ?> recognizer, IntStream input, ParserRuleContext ctx)
RecognitionExceptionback to summary
public RecognitionException(String message, Recognizer<Token, ?> recognizer, IntStream input, ParserRuleContext ctx)

Method Detail

getContextback to summary
public RuleContext getContext()

Gets the RuleContext at the time this exception was thrown.

If the context is not available, this method returns null.

Returns:RuleContext

The RuleContext at the time this exception was thrown. If the context is not available, this method returns null.

Annotations
@Nullable
getExpectedTokensback to summary
public IntervalSet 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:IntervalSet

The set of token types that could potentially follow the current state in the ATN, or null if the information is not available.

Annotations
@Nullable
getInputStreamback to summary
public IntStream 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:IntStream

The input stream which is the symbol source for the recognizer where this exception was thrown, or null if the stream is not available.

Annotations
@Nullable
getOffendingStateback to summary
public int getOffendingState()

Get the ATN state number the parser was in at the time the error occurred. For NoViableAltException and LexerNoViableAltException exceptions, this is the DecisionState number. For others, it is the state whose outgoing edge we couldn't match.

If the state number is not known, this method returns -1.

getOffendingTokenback to summary
public Token getOffendingToken()
Annotations
@Nullable
getOffendingTokenback to summary
public <T> T getOffendingToken(Recognizer<T, ?> recognizer)
Annotations
@SuppressWarnings:unchecked
getRecognizerback to summary
public Recognizer<?, ?> getRecognizer()

Gets the Recognizer where this exception occurred.

If the recognizer is not available, this method returns null.

Returns:Recognizer<?, ?>

The recognizer where this exception occurred, or null if the recognizer is not available.

Annotations
@Nullable
setOffendingStateback to summary
protected final void setOffendingState(int offendingState)
setOffendingTokenback to summary
protected final <Symbol extends Token> void setOffendingToken(Recognizer<Symbol, ?> recognizer, Symbol offendingToken)