ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4Exception.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file G4Exception.cc
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 //
28 //
29 // ----------------------------------------------------------------------
30 // G4Exception
31 // ----------------------------------------------------------------------
32 
33 #include "G4Exception.hh"
34 #include "G4StateManager.hh"
35 
36 void G4Exception(const char* originOfException,
37  const char* exceptionCode,
38  G4ExceptionSeverity severity,
39  const char* description)
40 {
41  G4VExceptionHandler* exceptionHandler
43  G4bool toBeAborted = true;
44  if(exceptionHandler)
45  {
46  toBeAborted = exceptionHandler
47  ->Notify(originOfException,exceptionCode,severity,description);
48  }
49  else
50  {
51  static const G4String& es_banner = G4ExceptionErrBannerStart();
52  static const G4String& ee_banner = G4ExceptionErrBannerEnd();
53  static const G4String& ws_banner = G4ExceptionWarnBannerStart();
54  static const G4String& we_banner = G4ExceptionWarnBannerEnd();
55  std::ostringstream message;
56  message << "\n*** ExceptionHandler is not defined ***\n"
57  << "*** G4Exception : " << exceptionCode << G4endl
58  << " issued by : " << originOfException << G4endl
59  << description << G4endl;
60  switch(severity)
61  {
62  case FatalException:
63  G4cerr << es_banner << message.str() << "*** Fatal Exception ***"
64  << ee_banner << G4endl;
65  break;
67  G4cerr << es_banner << message.str() << "*** Fatal Error In Argument ***"
68  << ee_banner << G4endl;
69  break;
70  case RunMustBeAborted:
71  G4cerr << es_banner << message.str() << "*** Run Must Be Aborted ***"
72  << ee_banner << G4endl;
73  break;
74  case EventMustBeAborted:
75  G4cerr << es_banner << message.str() << "*** Event Must Be Aborted ***"
76  << ee_banner << G4endl;
77  break;
78  default:
79  G4cout << ws_banner << message.str()
80  << "*** This is just a warning message. ***"
81  << we_banner << G4endl;
82  toBeAborted = false;
83  break;
84  }
85  }
86  if(toBeAborted)
87  {
89  {
90  G4cerr << G4endl << "*** G4Exception: Aborting execution ***" << G4endl;
91  abort();
92  }
93  else
94  {
95  G4cerr << G4endl << "*** G4Exception: Abortion suppressed ***"
96  << G4endl << "*** No guarantee for further execution ***" << G4endl;
97  }
98  }
99 }
100 
101 void G4Exception(const char* originOfException,
102  const char* exceptionCode,
103  G4ExceptionSeverity severity,
104  G4ExceptionDescription & description)
105 {
106  G4String des = description.str();
107  G4Exception(originOfException, exceptionCode, severity, des.c_str());
108 }
109 
110 void G4Exception(const char* originOfException,
111  const char* exceptionCode,
112  G4ExceptionSeverity severity,
113  G4ExceptionDescription & description,
114  const char* comments)
115 {
116  description << comments << G4endl;
117  G4Exception(originOfException, exceptionCode, severity, description);
118 }