Python Core API Error Handling¶
Catching errors¶
In versions <22.08 zhinst.ziPython
raised RuntimeError
in most error cases.
This made users to parse error message for a specific error type or code.
In version 22.08, the exceptions are overhauled and instead of RuntimeError
, a base error
CoreError
or its derivatives are raised.
To not break the existing 22.02 API, CoreError
derives from RuntimeError
and the error
message format is unchanged.
The package errors can be caught:
from zhinst.core import errors
try:
...
except errors.CoreError as error:
error_code = error.code
error_message = error.args[0]
Or if a specific zhinst.core
error is meant to be caught:
from zhinst.core import errors
try:
...
except errors.DeviceInUseError as error:
# Some action to handle the error
...
RuntimeError
can be used to catch the errors, but it is recommended to catch
the CoreError
or other package errors.
try:
...
except RuntimeError as error:
...
zhinst.core
error classes¶
zhinst.core.errors.CoreError(message, code=None)
¶
Bases: RuntimeError
Base error class for all zhinst.core exceptions.
All exceptions raised by this library should inherit from this class.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
message |
str
|
The error message |
required |
code |
Optional[int]
|
Optional internal LabOne error code |
None
|
code: t.Optional[int]
property
¶
Error code reported by LabOne.
Available error types:¶
Error Class | Base Classes |
---|---|
zhinst.core.errors.TimeoutError |
CoreError ,TimeoutError |
zhinst.core.errors.ConnectionError |
CoreError , ConnectionError |
zhinst.core.errors.ReadOnlyError |
CoreError |
zhinst.core.errors.NotFoundError |
CoreError |
zhinst.core.errors.DeviceInUseError |
CoreError |
zhinst.core.errors.DeviceNotFoundError |
CoreError |
zhinst.core.errors.InvalidArgumentError |
CoreError |
zhinst.core.errors.InvalidKeywordError |
CoreError |
zhinst.core.errors.DeviceInterfaceError |
CoreError |
zhinst.core.errors.SampleLossError |
CoreError , EOFError |