Geant4 9.6.0
Toolkit for the simulation of the passage of particles through matter
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
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$
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#include "G4ios.hh"
38#include "G4String.hh"
39#include "G4StateManager.hh"
40
41void G4Exception(const char* originOfException,
42 const char* exceptionCode,
43 G4ExceptionSeverity severity,
44 const char* description)
45{
46 G4VExceptionHandler* exceptionHandler
48 G4bool toBeAborted = true;
49 if(exceptionHandler)
50 {
51 toBeAborted = exceptionHandler
52 ->Notify(originOfException,exceptionCode,severity,description);
53 }
54 else
55 {
56 static const G4String es_banner
57 = "\n-------- EEEE ------- G4Exception-START -------- EEEE -------\n";
58 static const G4String ee_banner
59 = "\n-------- EEEE -------- G4Exception-END --------- EEEE -------\n";
60 static const G4String ws_banner
61 = "\n-------- WWWW ------- G4Exception-START -------- WWWW -------\n";
62 static const G4String we_banner
63 = "\n-------- WWWW -------- G4Exception-END --------- WWWW -------\n";
64 std::ostringstream message;
65 message << "\n*** ExceptionHandler is not defined ***\n"
66 << "*** G4Exception : " << exceptionCode << G4endl
67 << " issued by : " << originOfException << G4endl
68 << description << G4endl;
69 switch(severity)
70 {
71 case FatalException:
72 G4cerr << es_banner << message.str() << "*** Fatal Exception ***"
73 << ee_banner << G4endl;
74 break;
76 G4cerr << es_banner << message.str() << "*** Fatal Error In Argument ***"
77 << ee_banner << G4endl;
78 break;
80 G4cerr << es_banner << message.str() << "*** Run Must Be Aborted ***"
81 << ee_banner << G4endl;
82 break;
84 G4cerr << es_banner << message.str() << "*** Event Must Be Aborted ***"
85 << ee_banner << G4endl;
86 break;
87 default:
88 G4cout << ws_banner << message.str()
89 << "*** This is just a warning message. ***"
90 << we_banner << G4endl;
91 toBeAborted = false;
92 break;
93 }
94 }
95 if(toBeAborted)
96 {
98 {
99 G4cerr << G4endl << "*** G4Exception: Aborting execution ***" << G4endl;
100 abort();
101 }
102 else
103 {
104 G4cerr << G4endl << "*** G4Exception: Abortion suppressed ***"
105 << G4endl << "*** No guarantee for further execution ***" << G4endl;
106 }
107 }
108}
109
110void G4Exception(const char* originOfException,
111 const char* exceptionCode,
112 G4ExceptionSeverity severity,
113 G4ExceptionDescription & description)
114{
115 G4String des = description.str();
116 G4Exception(originOfException, exceptionCode, severity, des.c_str());
117}
118
119void G4Exception(const char* originOfException,
120 const char* exceptionCode,
121 G4ExceptionSeverity severity,
122 G4ExceptionDescription & description,
123 const char* comments)
124{
125 description << comments << G4endl;
126 G4Exception(originOfException, exceptionCode, severity, description);
127}
@ G4State_Abort
G4ExceptionSeverity
@ FatalException
@ FatalErrorInArgument
@ RunMustBeAborted
@ EventMustBeAborted
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
Definition: G4Exception.cc:41
bool G4bool
Definition: G4Types.hh:67
#define G4endl
Definition: G4ios.hh:52
G4DLLIMPORT std::ostream G4cerr
G4DLLIMPORT std::ostream G4cout
G4VExceptionHandler * GetExceptionHandler() const
static G4StateManager * GetStateManager()
virtual G4bool Notify(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)=0
std::ostringstream G4ExceptionDescription
Definition: globals.hh:76