# Class CayenneSqlException

java.lang.Object
java.lang.Throwable
java.lang.Exception
java.lang.RuntimeException
org.apache.cayenne.CayenneRuntimeException
org.apache.cayenne.CayenneSqlException

All Implemented Interfaces:
  `Serializable`

public class CayenneSqlException extends CayenneRuntimeException
An exception thrown when a failure occurs while executing a query statement or reading its results. It carries the `Query` being executed and the `TranslatedStatement` that was being executed at the time of the failure, and includes the statement's SQL in the exception message, so that a failure can be correlated with a specific query.

Since:
  5.0
See Also:
  - Serialized Form

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `CayenneSqlException(String message, Query query, TranslatedStatement statement, Throwable cause)`
  Creates an exception for a failure that happened while executing the provided query and statement.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `Query`
  `getQuery()`
  Returns the query that was being executed when the failure occurred, or null if it is not known.
  `TranslatedStatement`
  `getStatement()`
  Returns the statement that was being executed when the failure occurred, or null if it is not known.

  ### Methods inherited from class CayenneRuntimeException

  `getExceptionLabel, getMessage, getUnlabeledMessage`

  ### Methods inherited from class Throwable

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

  ### Methods inherited from class Object

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

- ## Constructor Details

  - ### CayenneSqlException

    public CayenneSqlException(String message, Query query, TranslatedStatement statement, Throwable cause)
    Creates an exception for a failure that happened while executing the provided query and statement. The statement may be null if the failure occurred before a statement was translated.

- ## Method Details

  - ### getQuery

    public Query getQuery()
    Returns the query that was being executed when the failure occurred, or null if it is not known.

  - ### getStatement

    public TranslatedStatement getStatement()
    Returns the statement that was being executed when the failure occurred, or null if it is not known.