Geant4 Cross Reference |
>> 1 // This code implementation is the intellectual property of >> 2 // the GEANT4 collaboration. 1 // 3 // 2 // ******************************************* << 4 // By copying, distributing or modifying the Program (or any work 3 // * License and Disclaimer << 5 // based on the Program) you indicate your acceptance of this statement, 4 // * << 6 // and all its terms. 5 // * The Geant4 software is copyright of th << 6 // * the Geant4 Collaboration. It is provided << 7 // * conditions of the Geant4 Software License << 8 // * LICENSE and available at http://cern.ch/ << 9 // * include a list of copyright holders. << 10 // * << 11 // * Neither the authors of this software syst << 12 // * institutes,nor the agencies providing fin << 13 // * work make any representation or warran << 14 // * regarding this software system or assum << 15 // * use. Please see the license in the file << 16 // * for the full disclaimer and the limitatio << 17 // * << 18 // * This code implementation is the result << 19 // * technical work of the GEANT4 collaboratio << 20 // * By using, copying, modifying or distri << 21 // * any work based on the software) you ag << 22 // * use in resulting scientific publicati << 23 // * acceptance of all terms of the Geant4 Sof << 24 // ******************************************* << 25 // 7 // 26 // G4Exception implementation << 8 // $Id: G4Exception.cc,v 1.8 1999/11/29 10:17:46 gcosmo Exp $ >> 9 // GEANT4 tag $Name: geant4-02-00 $ 27 // 10 // 28 // Authors: G.Cosmo, M.Asai - May 1999 - First << 11 // 29 // ------------------------------------------- << 12 // ---------------------------------------------------------------------- >> 13 // G4Exception >> 14 // >> 15 // Global error function prints string to G4cerr, and aborts >> 16 // program >> 17 // >> 18 // History: >> 19 // 30.06.95 P.Kent 30 20 31 #include "G4Exception.hh" << 32 #include "G4ios.hh" 21 #include "G4ios.hh" 33 #include "G4StateManager.hh" << 22 #include <stdlib.h> 34 #include "G4VExceptionHandler.hh" << 23 #include "g4rw/cstring.h" 35 24 36 namespace { << 25 void G4Exception(const char* s) 37 << 38 inline const G4String G4ExceptionErrBannerStar << 39 { 26 { 40 return "\n-------- EEEE ------- G4Exception- << 27 if (s) 41 } << 28 { 42 inline const G4String G4ExceptionWarnBannerSta << 29 G4cerr << s << G4endl; 43 { << 30 } 44 return "\n-------- WWWW ------- G4Exception- << 45 } << 46 31 47 inline const G4String G4ExceptionErrBannerEnd( << 32 G4cerr << G4endl << "*** G4Exception: Aborting execution ***" << G4endl; 48 { << 33 abort(); 49 return "\n-------- EEEE ------- G4Exception- << 50 } << 51 inline const G4String G4ExceptionWarnBannerEnd << 52 { << 53 return "\n-------- WWWW ------- G4Exception- << 54 } << 55 << 56 } // namespace << 57 << 58 // ------------------------------------------- << 59 void G4Exception(const char* originOfException << 60 G4ExceptionSeverity severity, << 61 { << 62 G4VExceptionHandler* exceptionHandler = << 63 G4StateManager::GetStateManager()->GetExce << 64 G4bool toBeAborted = true; << 65 if(exceptionHandler != nullptr) << 66 { << 67 toBeAborted = exceptionHandler->Notify(ori << 68 sev << 69 } << 70 else << 71 { << 72 static const G4String& es_banner = G4Excep << 73 static const G4String& ee_banner = G4Excep << 74 static const G4String& ws_banner = G4Excep << 75 static const G4String& we_banner = G4Excep << 76 std::ostringstream message; << 77 message << "\n*** ExceptionHandler is not << 78 << "*** G4Exception : " << excepti << 79 << " issued by : " << originO << 80 << description << G4endl; << 81 switch(severity) << 82 { << 83 case FatalException: << 84 G4cerr << es_banner << message.str() < << 85 << ee_banner << G4endl; << 86 break; << 87 case FatalErrorInArgument: << 88 G4cerr << es_banner << message.str() << 89 << "*** Fatal Error In Argument << 90 break; << 91 case RunMustBeAborted: << 92 G4cerr << es_banner << message.str() < << 93 << ee_banner << G4endl; << 94 break; << 95 case EventMustBeAborted: << 96 G4cerr << es_banner << message.str() < << 97 << ee_banner << G4endl; << 98 break; << 99 case JustWarning: << 100 G4cout << ws_banner << message.str() << 101 << "*** This is just a warning << 102 << G4endl; << 103 toBeAborted = false; << 104 break; << 105 default: << 106 toBeAborted = false; << 107 break; << 108 } << 109 } << 110 if(toBeAborted) << 111 { << 112 if(G4StateManager::GetStateManager()->SetN << 113 { << 114 G4cerr << G4endl << "*** G4Exception: Ab << 115 abort(); << 116 } << 117 else << 118 { << 119 G4cerr << G4endl << "*** G4Exception: Ab << 120 << "*** No guarantee for further << 121 } << 122 } << 123 } 34 } 124 35 125 // ------------------------------------------- << 36 void G4Exception(G4std::string s) 126 void G4Exception(const char* originOfException << 127 G4ExceptionSeverity severity, << 128 G4ExceptionDescription& descr << 129 { 37 { 130 G4String des = description.str(); << 38 G4Exception(s.c_str()); 131 G4Exception(originOfException, exceptionCode << 132 } 39 } 133 40 134 // ------------------------------------------- << 41 void G4Exception(G4String s) 135 void G4Exception(const char* originOfException << 136 G4ExceptionSeverity severity, << 137 G4ExceptionDescription& descr << 138 { 42 { 139 description << comments << G4endl; << 43 G4Exception(s.c_str()); 140 G4Exception(originOfException, exceptionCode << 141 } 44 } 142 45