Package org.codehaus.groovy.syntax

# Class TokenMismatchException

java.lang.Object
java.lang.Throwable
java.lang.Exception
org.codehaus.groovy.GroovyException
org.codehaus.groovy.syntax.SyntaxException
org.codehaus.groovy.syntax.TokenException
org.codehaus.groovy.syntax.TokenMismatchException

All Implemented Interfaces:
  `Serializable`, `GroovyExceptionInterface`

public class TokenMismatchException extends TokenException
Exception thrown when a parser encounters a token of an unexpected type. Contains information about both the unexpected token found and the expected token type. Extends `TokenException` to inherit token-based error reporting.

See Also:
  - Serialized Form

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `TokenMismatchException(Token token, int expectedType)`
  Constructs a TokenMismatchException.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `int`
  `getExpectedType()`
  Returns the token type that was expected.
  `Token`
  `getUnexpectedToken()`
  Returns the unexpected token that triggered this exception.

  ### Methods inherited from class org.codehaus.groovy.syntax.SyntaxException

  `getEndColumn, getEndLine, getLine, getMessage, getOriginalMessage, getSourceLocator, getStartColumn, getStartLine, setSourceLocator`

  ### Methods inherited from class org.codehaus.groovy.GroovyException

  `isFatal, setFatal`

  ### Methods inherited from class java.lang.Throwable

  `addSuppressed, fillInStackTrace, getCause, getLocalizedMessage, getStackTrace, getSuppressed, initCause, printStackTrace, printStackTrace, printStackTrace, setStackTrace, toString`

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

- ## Constructor Details

  - ### TokenMismatchException

    public TokenMismatchException(Token token, int expectedType)
    Constructs a TokenMismatchException.
    Parameters:
      `token` - the unexpected `Token` that was encountered
      `expectedType` - the expected token type from `Types`

- ## Method Details

  - ### getUnexpectedToken

    public Token getUnexpectedToken()
    Returns the unexpected token that triggered this exception.
    Returns:
      the unexpected `Token`

  - ### getExpectedType

    public int getExpectedType()
    Returns the token type that was expected.
    Returns:
      the expected token type from `Types`