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

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.

Constructor Summary

AccessConstructor and Description
public
public
RecognitionException(String message, Recognizer<?, ?> recognizer, IntStream input, ParserRuleContext ctx)

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.
getCtx
()

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 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 void
setOffendingToken(Token offendingToken)

Field Detail

ctxback to summary
private final RuleContext ctx
inputback to summary
private final IntStream input
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.

Constructor Detail

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

Method Detail

getCtxback to summary
public RuleContext getCtx()

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.

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.

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.

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()
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.

setOffendingStateback to summary
protected final void setOffendingState(int offendingState)
setOffendingTokenback to summary
protected final void setOffendingToken(Token offendingToken)