22 __all__ = [
"register",
"ExceptionMeta",
"Exception",
"LogicError",
23 "DomainError",
"InvalidParameterError",
"LengthError",
24 "OutOfRangeError",
"RuntimeError",
"RangeError",
"OverflowError",
25 "UnderflowError",
"NotFoundError",
"IoError",
"TypeError",
26 "translate",
"declare"]
31 from .
import exceptions
37 """A Python decorator that adds a Python exception wrapper to the registry that maps C++ Exceptions
38 to their Python wrapper classes.
40 registry[cls.WrappedClass] = cls
45 """A metaclass for custom exception wrappers, which adds lookup of class attributes
46 by delegating to the Swig-generated wrapper.
50 return getattr(cls.WrappedClass, name)
54 class Exception(builtins.Exception, metaclass=ExceptionMeta):
55 """The base class for Python-wrapped LSST C++ exceptions.
60 __module__ =
"lsst.pex.exceptions"
71 super(Exception, self).
__init__(message)
75 return getattr(self.
cpp, name)
78 return "%s('%s')" % (type(self).__name__, self.
cpp.what())
81 return self.
cpp.asString()
145 """Translate a C++ Exception instance to Python and return it."""
146 PyType = registry.get(type(cpp),
None)
148 warnings.warn(
"Could not find appropriate Python type for C++ Exception")
153 def declare(module, exception_name, base, wrapped_class):
154 """Declare a new exception."""
156 dict(WrappedClass=wrapped_class))))