00001 // @(#)root/pyroot:$Name: $:$Id: TPyException.h 31630 2009-12-08 10:21:36Z rdm $ 00002 // Author: Scott Snyder, Apr 2004 00003 00004 #ifndef ROOT_TPyException 00005 #define ROOT_TPyException 00006 00007 ////////////////////////////////////////////////////////////////////////////// 00008 // // 00009 // TPyException // 00010 // // 00011 // Purpose: A C++ exception class for throwing python exceptions // 00012 // through C++ code. // 00013 // Created: Apr, 2004, sss, from the version in D0's python_util. // 00014 // // 00015 // The situation is: // 00016 // - We're calling ROOT C++ code from python. // 00017 // - The C++ code can call back to python. // 00018 // - What to do then if the python callback throws an exception? // 00019 // // 00020 // We need to get the control flow back to where PyROOT makes the ROOT call.// 00021 // To do that we throw a TPyException. // 00022 // We can then catch this exception when we do the ROOT call. // 00023 // // 00024 // Note that we don't need to save any state in the exception -- it's // 00025 // already in the python error info variables. // 00026 // (??? Actually, if the program is multithreaded, this is dangerous // 00027 // if the code has released and reacquired the lock along the call chain. // 00028 // Punt on this for now, though.) // 00029 // // 00030 ////////////////////////////////////////////////////////////////////////////// 00031 00032 // ROOT 00033 #ifndef ROOT_DllImport 00034 #include "DllImport.h" 00035 #endif 00036 #ifndef ROOT_Rtypes 00037 #include "Rtypes.h" 00038 #endif 00039 00040 // Standard 00041 #include <exception> 00042 00043 00044 namespace PyROOT { 00045 00046 R__EXTERN void* TPyExceptionMagic; 00047 00048 class TPyException : public std::exception { 00049 public: 00050 // default constructor 00051 TPyException(); 00052 00053 // destructor 00054 virtual ~TPyException() throw(); 00055 00056 // give reason for raised exception 00057 virtual const char* what() const throw(); 00058 00059 ClassDef(TPyException,0) //C++ exception for throwing python exceptions 00060 }; 00061 00062 } // namespace PyROOT 00063 00064 #if defined(G__DICTIONARY) && defined(R__SOLARIS) 00065 // Force the inclusion of rw/math.h 00066 #include <limits> 00067 // Work around interaction between a struct named exception in math.h, 00068 // std::exception and the use of using namespace std; 00069 #if (__SUNPRO_CC < 0x5050) 00070 #define exception std::exception 00071 #endif 00072 #endif 00073 #endif