Geant4-11
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 "G4StateManager.hh"
33
34// --------------------------------------------------------------------
35void G4Exception(const char* originOfException, const char* exceptionCode,
36 G4ExceptionSeverity severity, const char* description)
37{
38 G4VExceptionHandler* exceptionHandler =
40 G4bool toBeAborted = true;
41 if(exceptionHandler != nullptr)
42 {
43 toBeAborted = exceptionHandler->Notify(originOfException, exceptionCode,
44 severity, description);
45 }
46 else
47 {
48 static const G4String& es_banner = G4ExceptionErrBannerStart();
49 static const G4String& ee_banner = G4ExceptionErrBannerEnd();
50 static const G4String& ws_banner = G4ExceptionWarnBannerStart();
51 static const G4String& we_banner = G4ExceptionWarnBannerEnd();
52 std::ostringstream message;
53 message << "\n*** ExceptionHandler is not defined ***\n"
54 << "*** G4Exception : " << exceptionCode << G4endl
55 << " issued by : " << originOfException << G4endl
56 << description << G4endl;
57 switch(severity)
58 {
59 case FatalException:
60 G4cerr << es_banner << message.str() << "*** Fatal Exception ***"
61 << ee_banner << G4endl;
62 break;
64 G4cerr << es_banner << message.str()
65 << "*** Fatal Error In Argument ***" << ee_banner << G4endl;
66 break;
68 G4cerr << es_banner << message.str() << "*** Run Must Be Aborted ***"
69 << ee_banner << G4endl;
70 break;
72 G4cerr << es_banner << message.str() << "*** Event Must Be Aborted ***"
73 << ee_banner << G4endl;
74 break;
75 default:
76 G4cout << ws_banner << message.str()
77 << "*** This is just a warning message. ***" << we_banner
78 << G4endl;
79 toBeAborted = false;
80 break;
81 }
82 }
83 if(toBeAborted)
84 {
86 {
87 G4cerr << G4endl << "*** G4Exception: Aborting execution ***" << G4endl;
88 abort();
89 }
90 else
91 {
92 G4cerr << G4endl << "*** G4Exception: Abortion suppressed ***" << G4endl
93 << "*** No guarantee for further execution ***" << G4endl;
94 }
95 }
96}
97
98// --------------------------------------------------------------------
99void G4Exception(const char* originOfException, const char* exceptionCode,
100 G4ExceptionSeverity severity,
101 G4ExceptionDescription& description)
102{
103 G4String des = description.str();
104 G4Exception(originOfException, exceptionCode, severity, des.c_str());
105}
106
107// --------------------------------------------------------------------
108void G4Exception(const char* originOfException, const char* exceptionCode,
109 G4ExceptionSeverity severity,
110 G4ExceptionDescription& description, const char* comments)
111{
112 description << comments << G4endl;
113 G4Exception(originOfException, exceptionCode, severity, description);
114}
@ G4State_Abort
G4ExceptionSeverity
@ FatalException
@ FatalErrorInArgument
@ RunMustBeAborted
@ EventMustBeAborted
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
Definition: G4Exception.cc:35
const G4String G4ExceptionErrBannerEnd()
Definition: G4Exception.hh:51
const G4String G4ExceptionErrBannerStart()
Definition: G4Exception.hh:42
const G4String G4ExceptionWarnBannerEnd()
Definition: G4Exception.hh:55
const G4String G4ExceptionWarnBannerStart()
Definition: G4Exception.hh:46
std::ostringstream G4ExceptionDescription
Definition: G4Exception.hh:40
bool G4bool
Definition: G4Types.hh:86
G4GLOB_DLL std::ostream G4cerr
#define G4endl
Definition: G4ios.hh:57
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