Geant4 11.2.2
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
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// G4Exception implementation
27//
28// Authors: G.Cosmo, M.Asai - May 1999 - First implementation
29// --------------------------------------------------------------------
30
31#include "G4Exception.hh"
32#include "G4ios.hh"
33#include "G4StateManager.hh"
35
36namespace {
37
38inline const G4String G4ExceptionErrBannerStart()
39{
40 return "\n-------- EEEE ------- G4Exception-START -------- EEEE -------\n";
41}
42inline const G4String G4ExceptionWarnBannerStart()
43{
44 return "\n-------- WWWW ------- G4Exception-START -------- WWWW -------\n";
45}
46
47inline const G4String G4ExceptionErrBannerEnd()
48{
49 return "\n-------- EEEE ------- G4Exception-END -------- EEEE -------\n";
50}
51inline const G4String G4ExceptionWarnBannerEnd()
52{
53 return "\n-------- WWWW ------- G4Exception-END -------- WWWW -------\n";
54}
55
56} // namespace
57
58// --------------------------------------------------------------------
59void G4Exception(const char* originOfException, const char* exceptionCode,
60 G4ExceptionSeverity severity, const char* description)
61{
62 G4VExceptionHandler* exceptionHandler =
64 G4bool toBeAborted = true;
65 if(exceptionHandler != nullptr)
66 {
67 toBeAborted = exceptionHandler->Notify(originOfException, exceptionCode,
68 severity, description);
69 }
70 else
71 {
72 static const G4String& es_banner = G4ExceptionErrBannerStart();
73 static const G4String& ee_banner = G4ExceptionErrBannerEnd();
74 static const G4String& ws_banner = G4ExceptionWarnBannerStart();
75 static const G4String& we_banner = G4ExceptionWarnBannerEnd();
76 std::ostringstream message;
77 message << "\n*** ExceptionHandler is not defined ***\n"
78 << "*** G4Exception : " << exceptionCode << G4endl
79 << " issued by : " << originOfException << G4endl
80 << description << G4endl;
81 switch(severity)
82 {
83 case FatalException:
84 G4cerr << es_banner << message.str() << "*** Fatal Exception ***"
85 << ee_banner << G4endl;
86 break;
88 G4cerr << es_banner << message.str()
89 << "*** Fatal Error In Argument ***" << ee_banner << G4endl;
90 break;
92 G4cerr << es_banner << message.str() << "*** Run Must Be Aborted ***"
93 << ee_banner << G4endl;
94 break;
96 G4cerr << es_banner << message.str() << "*** Event Must Be Aborted ***"
97 << ee_banner << G4endl;
98 break;
99 case JustWarning:
100 G4cout << ws_banner << message.str()
101 << "*** This is just a warning message. ***" << we_banner
102 << G4endl;
103 toBeAborted = false;
104 break;
105 default:
106 toBeAborted = false;
107 break;
108 }
109 }
110 if(toBeAborted)
111 {
113 {
114 G4cerr << G4endl << "*** G4Exception: Aborting execution ***" << G4endl;
115 abort();
116 }
117 else
118 {
119 G4cerr << G4endl << "*** G4Exception: Abortion suppressed ***" << G4endl
120 << "*** No guarantee for further execution ***" << G4endl;
121 }
122 }
123}
124
125// --------------------------------------------------------------------
126void G4Exception(const char* originOfException, const char* exceptionCode,
127 G4ExceptionSeverity severity,
128 G4ExceptionDescription& description)
129{
130 G4String des = description.str();
131 G4Exception(originOfException, exceptionCode, severity, des.c_str());
132}
133
134// --------------------------------------------------------------------
135void G4Exception(const char* originOfException, const char* exceptionCode,
136 G4ExceptionSeverity severity,
137 G4ExceptionDescription& description, const char* comments)
138{
139 description << comments << G4endl;
140 G4Exception(originOfException, exceptionCode, severity, description);
141}
@ G4State_Abort
G4ExceptionSeverity
@ JustWarning
@ FatalException
@ FatalErrorInArgument
@ RunMustBeAborted
@ EventMustBeAborted
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
std::ostringstream G4ExceptionDescription
bool G4bool
Definition G4Types.hh:86
G4GLOB_DLL std::ostream G4cerr
#define G4endl
Definition G4ios.hh:67
G4GLOB_DLL std::ostream G4cout
G4VExceptionHandler * GetExceptionHandler() const
static G4StateManager * GetStateManager()
virtual G4bool Notify(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)=0