00001 // @(#)root/pyroot:$Id: TPyException.cxx 20882 2007-11-19 11:31:26Z rdm $ 00002 // Author: Scott Snyder, Apr 2004 00003 00004 // Bindings 00005 #include "PyROOT.h" 00006 #include "TPyException.h" 00007 00008 00009 //______________________________________________________________________________ 00010 // C++ exception for throwing python exceptions 00011 // ============================================ 00012 // Purpose: A C++ exception class for throwing python exceptions 00013 // through C++ code. 00014 // Created: Apr, 2004, sss, from the version in D0's python_util. 00015 // 00016 // Note: Don't be tempted to declare the virtual functions defined here 00017 // as inline. 00018 // If you do, you may not be able to properly throw these 00019 // exceptions across shared libraries. 00020 00021 00022 //- data --------------------------------------------------------------------- 00023 ClassImp(PyROOT::TPyException) 00024 void* PyROOT::TPyExceptionMagic = (PyObject*)1; 00025 namespace { 00026 00027 class TManageMagic { // ensures that no valid PyObject can occupy the magic 00028 public: 00029 TManageMagic() { PyROOT::TPyExceptionMagic = new int(1); } 00030 ~TManageMagic() { delete (int*)PyROOT::TPyExceptionMagic; } 00031 } manageMagic; 00032 00033 } // unnamed namespace 00034 00035 00036 //- constructors/destructor -------------------------------------------------- 00037 PyROOT::TPyException::TPyException() 00038 { 00039 // default constructor 00040 } 00041 00042 PyROOT::TPyException::~TPyException() throw() 00043 { 00044 // destructor 00045 } 00046 00047 00048 //- public members ----------------------------------------------------------- 00049 const char* PyROOT::TPyException::what() const throw() 00050 { 00051 // Return reason for throwing this exception: a python exception was raised. 00052 return "python exception"; 00053 }