4 from .
import exceptionsLib
9 """A Python decorator that adds a Python exception wrapper to the registry that maps C++ Exceptions
10 to their Python wrapper classes.
12 registry[cls.WrappedClass] = cls
16 """A metaclass for custom exception wrappers, which adds lookup of class attributes
17 by delegating to the Swig-generated wrapper.
21 return getattr(self.WrappedClass, name)
25 """The base class for Python-wrapped LSST C++ exceptions.
28 __metaclass__ = ExceptionMeta
32 __module__ =
"lsst.pex.exceptions"
34 WrappedClass = exceptionsLib.Exception
37 if isinstance(arg, exceptionsLib.Exception):
43 super(Exception, self).
__init__(message)
47 return getattr(self.
cpp, name)
50 return "%s('%s')" % (type(self).__name__, self.cpp.what())
53 return self.cpp.asString()
57 WrappedClass = exceptionsLib.LogicError
61 WrappedClass = exceptionsLib.DomainError
65 WrappedClass = exceptionsLib.InvalidParameterError
69 WrappedClass = exceptionsLib.LengthError
73 WrappedClass = exceptionsLib.OutOfRangeError
77 WrappedClass = exceptionsLib.RuntimeError
81 WrappedClass = exceptionsLib.RangeError
85 WrappedClass = exceptionsLib.OverflowError
89 WrappedClass = exceptionsLib.UnderflowError
93 WrappedClass = exceptionsLib.NotFoundError
97 WrappedClass = exceptionsLib.MemoryError
101 WrappedClass = exceptionsLib.IoError
105 WrappedClass = exceptionsLib.TypeError
109 WrappedClass = exceptionsLib.TimeoutError
112 """Translate a C++ Exception instance to Python and return it."""
113 PyType = registry.get(type(cpp),
None)
115 warnings.warn(
"Could not find appropriate Python type for C++ Exception")