Exceptions#

Every Ginkgo exception derives from gko::Error, which carries the file, line and message and is itself a std::runtime_error. Catching gko::Error handles the exception types listed below.

Exception

Thrown when

NotSupported

it is not possible to perform the requested operation on the given object type

NotCompiled

an operation is called that is part of a module that was not compiled on the system

NotImplemented

an operation has not yet been implemented (but will be implemented in the future)

DimensionMismatch

an operation is applied to LinOps of incompatible size

BadDimension

an operation is applied to a LinOp with bad dimensions

ValueMismatch

two values are not equal

AllocationError

a memory allocation fails

OutOfBoundsError

a memory access is detected to be out of bounds

InvalidStateError

an object is in an invalid state

InvalidData

an object contains invalid data, described by the invariant it violated; raised by validate_data()

class Error #

Inherits from

  • public std::runtime_error

The Error class is used to report exceptional behaviour in library functions. Ginkgo uses C++ exception mechanism to this end, and the Error class represents a base class for all types of errors. The exact list of errors which could occur during the execution of a certain library routine is provided in the documentation of that routine, along with a short description of the situation when that error can occur. During runtime, these errors can be detected by using standard C++ try-catch blocks, and a human-readable error description can be obtained by calling the Error::what() method.

As an example, trying to compute a matrix-vector product with arguments of incompatible size will result in a DimensionMismatch error, which is demonstrated in the following program.

#include <ginkgo.h>
#include <iostream>

using namespace gko;

int main()
{
auto omp = create<OmpExecutor>();
auto A = randn_fill<matrix::Csr<float>>(5, 5, 0f, 1f, omp);
auto x = fill<matrix::Dense<float>>(6, 1, 1f, omp);
try {
auto y = apply(A, x);
    } catch(Error e) {
// an error occurred, write the message to screen and exit
        std::cout << e.what() << std::endl;
return -1;
    }
return 0;
}

Subclassed by

Public Functions

inline Error(
const std::string &file,
int line,
const std::string &what,
)#

Initializes an error.

Parameters:
  • file – The name of the offending source file

  • line – The source code line number where the error occurred

  • what – The error message

class NotSupported #

Inherits from

NotSupported is thrown in case it is not possible to perform the requested operation on the given object type.

class NotCompiled #

Inherits from

NotCompiled is thrown when attempting to call an operation which is a part of a module that was not compiled on the system.

class NotImplemented #

Inherits from

NotImplemented is thrown in case an operation has not yet been implemented (but will be implemented in the future).

class DimensionMismatch #

Inherits from

DimensionMismatch is thrown if an operation is being applied to LinOps of incompatible size.

class BadDimension #

Inherits from

BadDimension is thrown if an operation is being applied to a LinOp with bad dimensions.

class ValueMismatch #

Inherits from

ValueMismatch is thrown if two values are not equal.

class AllocationError #

Inherits from

AllocationError is thrown if a memory allocation fails.

class OutOfBoundsError #

Inherits from

OutOfBoundsError is thrown if a memory access is detected to be out-of-bounds.

class InvalidStateError #

Inherits from

Exception thrown if an object is in an invalid state.

class InvalidData #

Inherits from

InvalidData is thrown in case an object in Ginkgo contains invalid data, either because the data was user-provided, or because of a bug. Invalid data is described by the invariant it violated.