It is permissible for a reflected C++ function called from Python to throw an exception, as long as the exception inherits from IException. For example:
// C++ code
namespace ns
{
struct Apollo13Failure : public IException
{
virtual void Write(std::ostream& os) const
{
os << "Houston, we have a problem";
}
};
$function+ void FlyToMoon()
{
throw Apollo13Failure();
}
}
In the code below Python calls the function FlyToMoon() which throws an exception of type Apollo13Failure. As required, this inherits from IException. In Python, this causes a RuntimeError exception to be thrown, with a string value equal to the string written by the virtual Write() method of the C++ IException.
# python code
try:
ns.FlyToMoon()
except RuntimeError, e:
print e
which produces the following output:
Houston, we have a problem