Geant4  9.6.p02
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
pyG4ExceptionHandler.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: pyG4ExceptionHandler.cc,v 1.1 2006-11-21 05:58:33 kmura Exp $
27 // $Name: not supported by cvs2svn $
28 // ====================================================================
29 // pyG4ExceptionHandler.cc
30 //
31 // 2005 Q
32 // ====================================================================
33 #include <boost/python.hpp>
34 #include "G4VExceptionHandler.hh"
35 #include "G4StateManager.hh"
36 #include <stdlib.h>
37 
38 using namespace boost::python;
39 
40 // ====================================================================
41 // Python Exception Handler
42 // ====================================================================
44 public:
47  sm-> SetExceptionHandler(this);
48  }
50 
51  G4bool Notify(const char* originOfException,
52  const char* exceptionCode,
53  G4ExceptionSeverity severity,
54  const char* description) {
55 
56  std::ostringstream message;
57  message << "*** G4Exception : " << exceptionCode << G4endl
58  << " issued by : " << originOfException << G4endl
59  << description << G4endl;
60 
61  switch(severity) {
62  case FatalException:
63  PyErr_SetString(PyExc_AssertionError,
64  "*** Fatal Exception ***");
65  PyErr_Print();
66  G4cerr << message.str() << G4endl;
67  break;
68 
70  PyErr_SetString(PyExc_ValueError,
71  "*** Fatal Error In Argument ***");
72  PyErr_Print();
73  G4cerr << message.str() << G4endl;
74  break;
75 
76  case RunMustBeAborted:
77  PyErr_SetString(PyExc_RuntimeError,
78  "*** Run Must Be Aborted ***");
79  PyErr_Print();
80  G4cerr << message.str() << G4endl;
81  break;
82 
83  case EventMustBeAborted:
84  PyErr_SetString(PyExc_RuntimeError,
85  "*** Event Must Be Aborted ***");
86  PyErr_Print();
87  G4cerr << message.str() << G4endl;
88  break;
89 
90  default:
91  PyErr_Warn(PyExc_RuntimeWarning,
92  "*** This is just a warning message. ***");
93  G4cerr << message.str() << G4endl;
94  break;
95  }
96 
97  // anyway, no abort.
98  return false;
99  }
100 };
101 
102 // ====================================================================
103 // module definition
104 // ====================================================================
106 {
107  class_<PyG4ExceptionHandler, boost::noncopyable>
108  ("G4ExceptionHandler", "exception handler")
109  ;
110 }