source: trunk/environments/g4py/source/global/pyG4Exception.cc@ 1344

Last change on this file since 1344 was 1337, checked in by garnier, 15 years ago

tag geant4.9.4 beta 1 + modifs locales

File size: 4.9 KB
RevLine 
[1337]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,v 1.1 2006/11/20 05:57:16 kmura Exp $
27// $Name: geant4-09-04-beta-01 $
28// ====================================================================
29// pyG4Exception.cc
30//
31// 2005 Q
32// ====================================================================
33#include <boost/python.hpp>
34#include "G4StateManager.hh"
35#include "G4ExceptionSeverity.hh"
36
37using namespace boost::python;
38
39// ====================================================================
40// thin wrappers
41// ====================================================================
42namespace pyG4Exception {
43
44////////////////////////////////////////
45void f1_G4Exception(const char* message)
46////////////////////////////////////////
47{
48 if(message) {
49 G4cerr << message << G4endl;
50 }
51
52 if(G4StateManager::GetStateManager()->SetNewState(G4State_Abort,message)) {
53 G4cerr << G4endl << "*** G4Exception: Aborting execution ***" << G4endl;
54 PyErr_SetString(PyExc_RuntimeError, message);
55 PyErr_Print();
56 } else {
57 G4cerr << G4endl << "*** G4Exception: Abortion suppressed ***"
58 << G4endl << "*** No guarantee for further execution ***"
59 << G4endl;
60 }
61}
62
63
64//////////////////////////////////////////////////
65void f2_G4Exception(const char* originOfException,
66 const char* exceptionCode,
67 G4ExceptionSeverity severity,
68 const char* description)
69//////////////////////////////////////////////////
70{
71 G4VExceptionHandler* exceptionHandler
72 = G4StateManager::GetStateManager()-> GetExceptionHandler();
73 G4bool toBeAborted = true;
74 if(exceptionHandler) {
75 toBeAborted = exceptionHandler
76 -> Notify(originOfException,exceptionCode,severity,description);
77 } else {
78 G4cerr << G4endl
79 << "*** ExceptionHandler is not defined ***" << G4endl;
80 G4cerr << G4endl;
81 G4cerr << "*** G4Exception : " << exceptionCode << G4endl;
82 G4cerr << " issued by : " << originOfException << G4endl;
83 G4cerr << description << G4endl;
84 G4cerr << G4endl << "Severity : ";
85 switch(severity) {
86 case FatalException:
87 G4cerr << "*** Fatal Exception ***";
88 break;
89 case FatalErrorInArgument:
90 G4cerr << "*** Fatal Error In Argument ***";
91 break;
92 case RunMustBeAborted:
93 G4cerr << "*** Run Must Be Aborted ***";
94 break;
95 case EventMustBeAborted:
96 G4cerr << "*** Event Must Be Aborted ***";
97 break;
98 default:
99 G4cerr << "*** This is just a warning message. ***";
100 toBeAborted = false;
101 break;
102 }
103 G4cerr << G4endl;
104 }
105 if(toBeAborted) {
106 if(G4StateManager::GetStateManager()->SetNewState(G4State_Abort)) {
107 G4cerr << G4endl << "*** G4Exception: Aborting execution ***" << G4endl;
108 PyErr_SetString(PyExc_RuntimeError, description);
109 PyErr_Print();
110 } else {
111 G4cerr << G4endl << "*** G4Exception: Abortion suppressed ***"
112 << G4endl << "*** No guarantee for further execution ***"
113 << G4endl;
114 }
115 }
116}
117
118}
119
120using namespace pyG4Exception;
121
122// ====================================================================
123// module definition
124// ====================================================================
125void export_G4Exception()
126{
127 def("G4Exception", f1_G4Exception);
128 def("G4Exception", f2_G4Exception);
129
130}
Note: See TracBrowser for help on using the repository browser.