G4Exception.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 //
27 // $Id: G4Exception.cc 67970 2013-03-13 10:10:06Z gcosmo $
28 //
29 //
30 // ----------------------------------------------------------------------
31 // G4Exception
32 //
33 // Global error function prints string to G4cerr (or G4cout in case of
34 // warning). May abort program according to severity.
35 // ----------------------------------------------------------------------
36 //
37 // P.L. version. we do not want to create very large outputs
38 // to std out for "JustWarning" statements from the geometry Navigator..
39 //
40 
41 #include "G4ios.hh"
42 #include "G4String.hh"
43 #include "G4StateManager.hh"
44 
45 void G4Exception(const char* originOfException,
46  const char* exceptionCode,
47  G4ExceptionSeverity severity,
48  const char* description)
49 {
50  std::string exceptCodeStr(exceptionCode);
51 // bool skipPrintIt = exceptCodeStr.find("GeomNav") != std::string::npos;
52  bool skipPrintIt = exceptCodeStr.find("GeomNav") != std::string::npos;
53  if (severity == JustWarning && skipPrintIt) return;
54  G4VExceptionHandler* exceptionHandler
55  = G4StateManager::GetStateManager()->GetExceptionHandler();
56  G4bool toBeAborted = true;
57  if(exceptionHandler)
58  {
59  toBeAborted = exceptionHandler
60  ->Notify(originOfException,exceptionCode,severity,description);
61  }
62  else
63  {
64  static const G4String es_banner
65  = "\n-------- EEEE ------- G4Exception-START -------- EEEE -------\n";
66  static const G4String ee_banner
67  = "\n-------- EEEE -------- G4Exception-END --------- EEEE -------\n";
68  static const G4String ws_banner
69  = "\n-------- WWWW ------- G4Exception-START -------- WWWW -------\n";
70  static const G4String we_banner
71  = "\n-------- WWWW -------- G4Exception-END --------- WWWW -------\n";
72  std::ostringstream message;
73  message << "\n*** ExceptionHandler is not defined ***\n"
74  << "*** G4Exception : " << exceptionCode << G4endl
75  << " issued by : " << originOfException << G4endl
76  << description << G4endl;
77  switch(severity)
78  {
79  case FatalException:
80  G4cerr << es_banner << message.str() << "*** Fatal Exception ***"
81  << ee_banner << G4endl;
82  break;
83  case FatalErrorInArgument:
84  G4cerr << es_banner << message.str() << "*** Fatal Error In Argument ***"
85  << ee_banner << G4endl;
86  break;
87  case RunMustBeAborted:
88  G4cerr << es_banner << message.str() << "*** Run Must Be Aborted ***"
89  << ee_banner << G4endl;
90  break;
91  case EventMustBeAborted:
92  G4cerr << es_banner << message.str() << "*** Event Must Be Aborted ***"
93  << ee_banner << G4endl;
94  break;
95  default:
96  G4cout << ws_banner << message.str()
97  << "*** This is just a warning message. ***"
98  << we_banner << G4endl;
99  toBeAborted = false;
100  break;
101  }
102  }
103  if(toBeAborted)
104  {
105  if(G4StateManager::GetStateManager()->SetNewState(G4State_Abort))
106  {
107  G4cerr << G4endl << "*** G4Exception: Aborting execution ***" << G4endl;
108  abort();
109  }
110  else
111  {
112  G4cerr << G4endl << "*** G4Exception: Abortion suppressed ***"
113  << G4endl << "*** No guarantee for further execution ***" << G4endl;
114  }
115  }
116 }
117 
118 void G4Exception(const char* originOfException,
119  const char* exceptionCode,
120  G4ExceptionSeverity severity,
121  G4ExceptionDescription & description)
122 {
123  G4String des = description.str();
124  G4Exception(originOfException, exceptionCode, severity, des.c_str());
125 }
126 
127 void G4Exception(const char* originOfException,
128  const char* exceptionCode,
129  G4ExceptionSeverity severity,
130  G4ExceptionDescription & description,
131  const char* comments)
132 {
133  description << comments << G4endl;
134  G4Exception(originOfException, exceptionCode, severity, description);
135 }
std::string string
Definition: nybbler.cc:12
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
Definition: G4Exception.cc:45
static QList< CommentInPrepass > comments