Geant4  v4-10.4-release
 모두 클래스 네임스페이스들 파일들 함수 변수 타입정의 열거형 타입 열거형 멤버 Friends 매크로 그룹들 페이지들
G4Exception.hh
이 파일의 문서화 페이지로 가기
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 #ifndef G4EXCEPTION_HH
38 #define G4EXCEPTION_HH
39 
40 #include "G4ios.hh"
41 #include "G4String.hh"
42 #include "G4StateManager.hh"
43 #include "G4VExceptionHandler.hh"
44 
45 typedef std::ostringstream G4ExceptionDescription;
46 
48 {
49  return "\n-------- EEEE ------- G4Exception-START -------- EEEE -------\n";
50 }
52 {
53  return "\n-------- WWWW ------- G4Exception-START -------- WWWW -------\n";
54 }
55 
57 {
58  return "\n-------- EEEE ------- G4Exception-END -------- EEEE -------\n";
59 }
61 {
62  return "\n-------- WWWW ------- G4Exception-END -------- WWWW -------\n";
63 }
64 
65 inline void G4Exception(const char* originOfException,
66  const char* exceptionCode,
67  G4ExceptionSeverity severity,
68  const char* description)
69 {
70  G4VExceptionHandler* exceptionHandler
72  G4bool toBeAborted = true;
73  if(exceptionHandler)
74  {
75  toBeAborted = exceptionHandler
76  ->Notify(originOfException,exceptionCode,severity,description);
77  }
78  else
79  {
80  static const G4String& es_banner = G4ExceptionErrBannerStart();
81  static const G4String& ee_banner = G4ExceptionErrBannerEnd();
82  static const G4String& ws_banner = G4ExceptionWarnBannerStart();
83  static const G4String& we_banner = G4ExceptionWarnBannerEnd();
84  std::ostringstream message;
85  message << "\n*** ExceptionHandler is not defined ***\n"
86  << "*** G4Exception : " << exceptionCode << G4endl
87  << " issued by : " << originOfException << G4endl
88  << description << G4endl;
89  switch(severity)
90  {
91  case FatalException:
92  G4cerr << es_banner << message.str() << "*** Fatal Exception ***"
93  << ee_banner << G4endl;
94  break;
96  G4cerr << es_banner << message.str() << "*** Fatal Error In Argument ***"
97  << ee_banner << G4endl;
98  break;
99  case RunMustBeAborted:
100  G4cerr << es_banner << message.str() << "*** Run Must Be Aborted ***"
101  << ee_banner << G4endl;
102  break;
103  case EventMustBeAborted:
104  G4cerr << es_banner << message.str() << "*** Event Must Be Aborted ***"
105  << ee_banner << G4endl;
106  break;
107  default:
108  G4cout << ws_banner << message.str()
109  << "*** This is just a warning message. ***"
110  << we_banner << G4endl;
111  toBeAborted = false;
112  break;
113  }
114  }
115  if(toBeAborted)
116  {
118  {
119  G4cerr << G4endl << "*** G4Exception: Aborting execution ***" << G4endl;
120  abort();
121  }
122  else
123  {
124  G4cerr << G4endl << "*** G4Exception: Abortion suppressed ***"
125  << G4endl << "*** No guarantee for further execution ***" << G4endl;
126  }
127  }
128 }
129 
130 inline void G4Exception(const char* originOfException,
131  const char* exceptionCode,
132  G4ExceptionSeverity severity,
133  G4ExceptionDescription & description)
134 {
135  G4String des = description.str();
136  G4Exception(originOfException, exceptionCode, severity, des.c_str());
137 }
138 
139 inline void G4Exception(const char* originOfException,
140  const char* exceptionCode,
141  G4ExceptionSeverity severity,
142  G4ExceptionDescription & description,
143  const char* comments)
144 {
145  description << comments << G4endl;
146  G4Exception(originOfException, exceptionCode, severity, description);
147 }
148 
149 #endif /* G4EXCEPTION_HH */
std::ostringstream G4ExceptionDescription
Definition: G4Exception.hh:45
const G4String G4ExceptionWarnBannerStart()
Definition: G4Exception.hh:51
#define G4endl
Definition: G4ios.hh:61
G4VExceptionHandler * GetExceptionHandler() const
void message(RunManager *runmanager)
Definition: ts_scorers.cc:72
const G4String G4ExceptionErrBannerStart()
Definition: G4Exception.hh:47
bool G4bool
Definition: G4Types.hh:79
G4GLOB_DLL std::ostream G4cerr
G4ExceptionSeverity
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
Definition: G4Exception.hh:65
G4GLOB_DLL std::ostream G4cout
virtual G4bool Notify(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)=0
const G4String G4ExceptionErrBannerEnd()
Definition: G4Exception.hh:56
static G4StateManager * GetStateManager()
const G4String G4ExceptionWarnBannerEnd()
Definition: G4Exception.hh:60