Commit c43ea297 authored by Georg Schölly's avatar Georg Schölly Committed by Georg Schölly

store status code in UaStatusCodeError

This allows the user to handle some status codes differently
from others.
parent 7074ac7a
......@@ -2,14 +2,38 @@
Define exceptions to be raised at various places in the stack
"""
class UaError(RuntimeError):
pass
class UaStatusCodeError(UaError):
pass
"""
This exception is raised when a bad status code is encountered.
It exposes the status code number in the `code' property, so the
user can distinguish between the different status codes and maybe
handle some of them.
The list of status error codes can be found in opcua.ua.status_codes.
"""
def __init__(self, code):
"""
:param code: The code of the exception. (Should be a number.)
"""
UaError.__init__(self, code)
def __str__(self):
# import here to avoid circular import problems
import opcua.ua.status_codes as status_codes
return "{1}({0})".format(*status_codes.get_name_and_doc(self.code))
@property
def code(self):
"""
The code of the status error.
"""
return self.args[0]
class UaStringParsingError(UaError):
pass
......@@ -450,11 +450,12 @@ class StatusCode(FrozenClass):
def check(self):
"""
raise en exception if status code is anything else than 0
use is is_good() method if not exception is desired
Raises an exception if the status code is anything else than 0 (good).
Use the is_good() method if you do not want an exception.
"""
if self.value != 0:
raise UaStatusCodeError("{}({})".format(self.doc, self.name))
raise UaStatusCodeError(self.value)
def is_good(self):
"""
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment