class PyComediError (Exception):
"Error in pycomedi"
- pass
+ def __init__(self, function_name=None, ret=None, comedi_msg=None,
+ error_msg=None):
+ self.function_name = function_name
+ self.ret = ret
+ self.comedi_msg = comedi_msg
+ self.error_msg = error_msg
+ if error_msg:
+ msg = '{} ({}): {} ({})'.format(
+ function_name, error_msg, comedi_msg, ret)
+ else:
+ msg = '{}: {} ({})'.format(function_name, comedi_msg, ret)
+ super(PyComediError, self).__init__(msg)
cimport _comedilib_h
-def raise_error(function_name='', ret=None, error_msg=None):
+def raise_error(function_name=None, ret=None, error_msg=None):
"""Report an error while executing a comedilib function
+ >>> from pycomedi import PyComediError
>>> raise_error(function_name='myfn', ret=-1)
Traceback (most recent call last):
...
Traceback (most recent call last):
...
PyComediError: myfn (some error): Success (-1)
+ >>> try:
+ ... raise_error(function_name='myfn', ret=-1)
+ ... except PyComediError, e:
+ ... print(e.function_name)
+ ... print(e.ret)
+ myfn
+ -1
"""
errno = _comedilib_h.comedi_errno()
comedi_msg = _comedilib_h.comedi_strerror(errno)
- #_comedilib_h.comedi_perror(function_name)
- if error_msg:
- msg = '%s (%s): %s (%s)' % (function_name, error_msg, comedi_msg, ret)
- else:
- msg = '%s: %s (%s)' % (function_name, comedi_msg, ret)
- raise _PyComediError(msg)
+ raise _PyComediError(
+ function_name=function_name, ret=ret, comedi_msg=comedi_msg,
+ error_msg=error_msg)
def _comedi_getter(name, is_invalid):