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 |
|
|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
API details¶
- class hdrl.core.Error(*args)¶
Bases:
Exception,SequenceAbstract 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.