Error classes

class tf.OpError

A generic error that is raised when TensorFlow execution fails.

Whenever possible, the session will raise a more specific subclass of OpError from the tf.errors module.


The operation that failed, if known.

N.B. If the failed op was synthesized at runtime, e.g. a Send or Recv op, there will be no corresponding Operation object. In that case, this will return None, and you should instead use the OpError.node_def to discover information about the op.


The Operation that failed, or None.


The NodeDef proto representing the op that failed.

Other Methods

tf.OpError.__init__(node_def, op, message, error_code) {:#OpError.init}

Creates a new OpError indicating that a particular op failed.

  • node_def: The node_def_pb2.NodeDef proto representing the op that failed, if known; otherwise None.
  • op: The ops.Operation that failed, if known; otherwise None.
  • message: The message string describing the failure.
  • error_code: The error_codes_pb2.Code describing the error.

tf.OpError.__str__() {:#OpError.str}


The integer error code that describes the error.


The error message that describes the error.

class tf.errors.CancelledError

Raised when an operation or step is cancelled.

For example, a long-running operation (e.g. queue.enqueue() may be cancelled by running another operation (e.g. queue.close(cancel_pending_enqueues=True), or by closing the session. A step that is running such a long-running operation will fail by raising CancelledError.

tf.errors.CancelledError.__init__(node_def, op, message) {:#CancelledError.init}

Creates a CancelledError.

class tf.errors.UnknownError

Unknown error.

An example of where this error may be returned is if a Status value received from another address space belongs to an error-space that is not known to this address space. Also errors raised by APIs that do not return enough error information may be converted to this error.

tf.errors.UnknownError.__init__(node_def, op, message, error_code=2) {:#UnknownError.init}

Creates an UnknownError.

class tf.errors.InvalidArgumentError

Raised when an operation receives an invalid argument.

This may occur, for example, if an operation is receives an input tensor that has an invalid value or shape. For example, the tf.matmul() op will raise this error if it receives an input that is not a matrix, and the tf.reshape() op will raise this error if the new shape does not match the number of elements in the input tensor.

tf.errors.InvalidArgumentError.__init__(node_def, op, message) {:#InvalidArgumentError.init}

Creates an InvalidArgumentError.

class tf.errors.DeadlineExceededError

Raised when a deadline expires before an operation could complete.

This exception is not currently used.

tf.errors.DeadlineExceededError.__init__(node_def, op, message) {:#DeadlineExceededError.init}

Creates a DeadlineExceededError.

class tf.errors.NotFoundError

Raised when a requested entity (e.g., a file or directory) was not found.

For example, running the operation could raise NotFoundError if it receives the name of a file that does not exist.

tf.errors.NotFoundError.__init__(node_def, op, message) {:#NotFoundError.init}

Creates a NotFoundError.

class tf.errors.AlreadyExistsError

Raised when an entity that we attempted to create already exists.

For example, running an operation that saves a file (e.g. could potentially raise this exception if an explicit filename for an existing file was passed.

tf.errors.AlreadyExistsError.__init__(node_def, op, message) {:#AlreadyExistsError.init}

Creates an AlreadyExistsError.

class tf.errors.PermissionDeniedError

Raised when the caller does not have permission to run an operation.

For example, running the operation could raise PermissionDeniedError if it receives the name of a file for which the user does not have the read file permission.

tf.errors.PermissionDeniedError.__init__(node_def, op, message) {:#PermissionDeniedError.init}

Creates a PermissionDeniedError.

class tf.errors.UnauthenticatedError

The request does not have valid authentication credentials.

This exception is not currently used.

tf.errors.UnauthenticatedError.__init__(node_def, op, message) {:#UnauthenticatedError.init}

Creates an UnauthenticatedError.

class tf.errors.ResourceExhaustedError

Some resource has been exhausted.

For example, this error might be raised if a per-user quota is exhausted, or perhaps the entire file system is out of space.

tf.errors.ResourceExhaustedError.__init__(node_def, op, message) {:#ResourceExhaustedError.init}

Creates a ResourceExhaustedError.

class tf.errors.FailedPreconditionError

Operation was rejected because the system is not in a state to execute it.

This exception is most commonly raised when running an operation that reads a tf.Variable before it has been initialized.

tf.errors.FailedPreconditionError.__init__(node_def, op, message) {:#FailedPreconditionError.init}

Creates a FailedPreconditionError.

class tf.errors.AbortedError

The operation was aborted, typically due to a concurrent action.

For example, running a queue.enqueue() operation may raise AbortedError if a queue.close() operation previously ran.

tf.errors.AbortedError.__init__(node_def, op, message) {:#AbortedError.init}

Creates an AbortedError.

class tf.errors.OutOfRangeError

Raised when an operation iterates past the valid input range.

This exception is raised in "end-of-file" conditions, such as when a queue.dequeue() operation is blocked on an empty queue, and a queue.close() operation executes.

tf.errors.OutOfRangeError.__init__(node_def, op, message) {:#OutOfRangeError.init}

Creates an OutOfRangeError.

class tf.errors.UnimplementedError

Raised when an operation has not been implemented.

Some operations may raise this error when passed otherwise-valid arguments that it does not currently support. For example, running the tf.nn.max_pool() operation would raise this error if pooling was requested on the batch dimension, because this is not yet supported.

tf.errors.UnimplementedError.__init__(node_def, op, message) {:#UnimplementedError.init}

Creates an UnimplementedError.

class tf.errors.InternalError

Raised when the system experiences an internal error.

This exception is raised when some invariant expected by the runtime has been broken. Catching this exception is not recommended.

tf.errors.InternalError.__init__(node_def, op, message) {:#InternalError.init}

Creates an InternalError.

class tf.errors.UnavailableError

Raised when the runtime is currently unavailable.

This exception is not currently used.

tf.errors.UnavailableError.__init__(node_def, op, message) {:#UnavailableError.init}

Creates an UnavailableError.

class tf.errors.DataLossError

Raised when unrecoverable data loss or corruption is encountered.

For example, this may be raised by running a operation, if the file is truncated while it is being read.

tf.errors.DataLossError.__init__(node_def, op, message) {:#DataLossError.init}

Creates a DataLossError.