Geant4_10
pyG4Exception.cc
Go to the documentation of this file.
1 //
2 // ********************************************************************
3 // * License and Disclaimer *
4 // * *
5 // * The Geant4 software is copyright of the Copyright Holders of *
6 // * the Geant4 Collaboration. It is provided under the terms and *
7 // * conditions of the Geant4 Software License, included in the file *
8 // * LICENSE and available at http://cern.ch/geant4/license . These *
9 // * include a list of copyright holders. *
10 // * *
11 // * Neither the authors of this software system, nor their employing *
12 // * institutes,nor the agencies providing financial support for this *
13 // * work make any representation or warranty, express or implied, *
14 // * regarding this software system or assume any liability for its *
15 // * use. Please see the license in the file LICENSE and URL above *
16 // * for the full disclaimer and the limitation of liability. *
17 // * *
18 // * This code implementation is the result of the scientific and *
19 // * technical work of the GEANT4 collaboration. *
20 // * By using, copying, modifying or distributing the software (or *
21 // * any work based on the software) you agree to acknowledge its *
22 // * use in resulting scientific publications, and indicate your *
23 // * acceptance of all terms of the Geant4 Software license. *
24 // ********************************************************************
25 //
26 // $Id: pyG4Exception.cc 66892 2013-01-17 10:57:59Z gunter $
27 // ====================================================================
28 // pyG4Exception.cc
29 //
30 // 2005 Q
31 // ====================================================================
32 #include <boost/python.hpp>
33 #include "G4StateManager.hh"
34 #include "G4ExceptionSeverity.hh"
35 
36 using namespace boost::python;
37 
38 // ====================================================================
39 // thin wrappers
40 // ====================================================================
41 namespace pyG4Exception {
42 
44 void f2_G4Exception(const char* originOfException,
45  const char* exceptionCode,
46  G4ExceptionSeverity severity,
47  const char* description)
49 {
50  G4VExceptionHandler* exceptionHandler
51  = G4StateManager::GetStateManager()-> GetExceptionHandler();
52  G4bool toBeAborted = true;
53  if(exceptionHandler) {
54  toBeAborted = exceptionHandler
55  -> Notify(originOfException,exceptionCode,severity,description);
56  } else {
57  G4String e_banner = "\n!!!!! - !!!!! - !!!!! - !!!!! - !!!!! - !!!!!\n";
58  G4String w_banner = "\nwwwww - wwwww - wwwww - wwwww - wwwww - wwwww\n";
59  std::ostringstream message;
60  message << "\n*** ExceptionHandler is not defined ***\n"
61  << "*** G4Exception : " << exceptionCode << G4endl
62  << " issued by : " << originOfException << G4endl
63  << description << G4endl;
64  switch(severity) {
65  case FatalException:
66  G4cerr << e_banner << message.str() << "*** Fatal Exception ***"
67  << e_banner;
68  break;
70  G4cerr << e_banner << message.str() << "*** Fatal Error In Argument ***"
71  << e_banner;
72  break;
73  case RunMustBeAborted:
74  G4cerr << e_banner << message.str() << "*** Run Must Be Aborted ***"
75  << e_banner;
76  break;
77  case EventMustBeAborted:
78  G4cerr << e_banner << message.str() << "*** Event Must Be Aborted ***"
79  << e_banner;
80  break;
81  default:
82  G4cout << w_banner << message.str()
83  << "*** This is just a warning message. ***"
84  << w_banner;
85  toBeAborted = false;
86  break;
87  }
88  }
89 
90  if(toBeAborted) {
92  G4cerr << G4endl << "*** G4Exception: Aborting execution ***" << G4endl;
93  PyErr_SetString(PyExc_RuntimeError, description);
94  PyErr_Print();
95  } else {
96  G4cerr << G4endl << "*** G4Exception: Abortion suppressed ***"
97  << G4endl << "*** No guarantee for further execution ***"
98  << G4endl;
99  }
100  }
101 }
102 
103 }
104 
105 using namespace pyG4Exception;
106 
107 // ====================================================================
108 // module definition
109 // ====================================================================
111 {
112  def("G4Exception", f2_G4Exception);
113 }
static G4StateManager * GetStateManager()
G4GLOB_DLL std::ostream G4cout
bool G4bool
Definition: G4Types.hh:79
G4ExceptionSeverity
#define G4endl
Definition: G4ios.hh:61
void export_G4Exception()
void f2_G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
G4GLOB_DLL std::ostream G4cerr