Errors

PyHDRL raises subclasses of hdrl.core.Error when an underlying CPL/HDRL call sets a CPL error. These are the same CPL_ERROR_* codes used by PyCPL; they live under the hdrl.core namespace so recipe code can catch HDRL failures without importing every PyCPL exception.

Catch hdrl.core.Error for any CPL/HDRL error translated by the binding, or a specific subclass when you need to handle one code. Python argument validation can instead raise built-in exceptions such as TypeError or ValueError.

CPL code → hdrl.core exception

CPL error code

hdrl.core class

CPL_ERROR_UNSPECIFIED

UnspecifiedError

CPL_ERROR_HISTORY_LOST

ErrorLostError

CPL_ERROR_DUPLICATING_STREAM

DuplicatingStreamError

CPL_ERROR_ASSIGNING_STREAM

AssigningStreamError

CPL_ERROR_FILE_IO

FileIOError

CPL_ERROR_BAD_FILE_FORMAT

BadFileFormatError

CPL_ERROR_FILE_ALREADY_OPEN

FileAlreadyOpenError

CPL_ERROR_FILE_NOT_CREATED

FileNotCreatedError

CPL_ERROR_FILE_NOT_FOUND

FileNotFoundError

CPL_ERROR_DATA_NOT_FOUND

DataNotFoundError

CPL_ERROR_ACCESS_OUT_OF_RANGE

AccessOutOfRangeError

CPL_ERROR_NULL_INPUT

NullInputError

CPL_ERROR_INCOMPATIBLE_INPUT

IncompatibleInputError

CPL_ERROR_ILLEGAL_INPUT

IllegalInputError

CPL_ERROR_ILLEGAL_OUTPUT

IllegalOutputError

CPL_ERROR_UNSUPPORTED_MODE

UnsupportedModeError

CPL_ERROR_SINGULAR_MATRIX

SingularMatrixError

CPL_ERROR_DIVISION_BY_ZERO

DivisionByZeroError

CPL_ERROR_TYPE_MISMATCH

TypeMismatchError

CPL_ERROR_INVALID_TYPE

InvalidTypeError

CPL_ERROR_CONTINUE

ContinueError

CPL_ERROR_NO_WCS

NoWCSError

CPL_ERROR_EOL

EOLError

API details

class hdrl.core.Error(*args)

Bases: Exception, Sequence

Abstract base class of all CPL exceptions, Do not instantiate this class, instead use hdrl.core.NullInputError, hdrl.core.InvalidArgumentError, or any other subclass. However this class implements has all documentation for those error subclasses.

In order to copy a cpl error, where you do not know the type of the error, use the hdrl.core.Error.create classmethod, as create can dispatch to the relevant subclass.

Examples

try:
    # Some PyCPL functions are called here
except hdrl.core.IllegalInputError as e:
    print(str(e.message))
except hdrl.core.Error as e:
    print(str(e))
classmethod create(*args)

Create a subclass of Error, choosing subclass based on input arguments, so you don’t need to know which subclass of error to create one. Instantiating a InvalidTypeError, FileIOError, etc… are preferred over using this function, when you know the error you’re creating.

This method has several overloads:
  • (copy: Error) Copy constructor copies the given error

  • (trace: List of Error) Given a list of Errors, this creates a stack trace out of those errors (essentially concatenating them) and produces a type the same as the final error in the list

  • (code: int, function_name: str, file_name: str, line: unsigned, error_message: str) Creates a new error, (Only 1 frame in the trace) based on CPL error code Cpl error codes are available on subclasses as the ‘code’ class member e.g. IllegalInputError.code

  • (data: _Error_Data) Since Error is a wrapper around _Error_Data, this is the main constructor

The class that is returned is a subclass of hdrl.core.Error

property file

C/C++ File where this error occurred or was re-thrown

property function
property line

Line number (in a C/C++ file) where this error or was re-thrown

property message
property trace
class hdrl.core.ErrorFrame

Bases: pybind11_object

error_class(self: hdrl.core.ErrorFrame) → object
property code
property file
property function
property line
property message

The concrete *Error subclasses are listed in the table above. Each subclass sets a fixed code attribute equal to the corresponding CPL integer code.