[833] | 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: G4Exception.cc,v 1.21 2007/11/13 17:35:06 gcosmo Exp $ |
---|
[850] | 28 | // GEANT4 tag $Name: HEAD $ |
---|
[833] | 29 | // |
---|
| 30 | // |
---|
| 31 | // ---------------------------------------------------------------------- |
---|
| 32 | // G4Exception |
---|
| 33 | // |
---|
| 34 | // Global error function prints string to G4cerr, and aborts |
---|
| 35 | // program |
---|
| 36 | // |
---|
| 37 | // History: |
---|
| 38 | // 30.06.95 P.Kent |
---|
| 39 | |
---|
| 40 | #include "G4ios.hh" |
---|
| 41 | #include "G4String.hh" |
---|
| 42 | #include "G4StateManager.hh" |
---|
| 43 | |
---|
| 44 | void G4Exception(const char* emessage) |
---|
| 45 | { |
---|
| 46 | if(emessage) { G4cerr << emessage << G4endl; } |
---|
| 47 | if(G4StateManager::GetStateManager()->SetNewState(G4State_Abort,emessage)) |
---|
| 48 | { |
---|
| 49 | G4cerr << G4endl << "*** G4Exception: Aborting execution ***" << G4endl; |
---|
| 50 | abort(); |
---|
| 51 | } |
---|
| 52 | else |
---|
| 53 | { |
---|
| 54 | G4cerr << G4endl << "*** G4Exception: Abortion suppressed ***" |
---|
| 55 | << G4endl << "*** No guarantee for further execution ***" << G4endl; |
---|
| 56 | } |
---|
| 57 | } |
---|
| 58 | |
---|
| 59 | void G4Exception(const char* originOfException, |
---|
| 60 | const char* exceptionCode, |
---|
| 61 | G4ExceptionSeverity severity, |
---|
| 62 | const char* description) |
---|
| 63 | { |
---|
| 64 | G4VExceptionHandler* exceptionHandler |
---|
| 65 | = G4StateManager::GetStateManager()->GetExceptionHandler(); |
---|
| 66 | G4bool toBeAborted = true; |
---|
| 67 | if(exceptionHandler) |
---|
| 68 | { |
---|
| 69 | toBeAborted = exceptionHandler |
---|
| 70 | ->Notify(originOfException,exceptionCode,severity,description); |
---|
| 71 | } |
---|
| 72 | else |
---|
| 73 | { |
---|
| 74 | G4cerr << G4endl |
---|
| 75 | << "*** ExceptionHandler is not defined ***" << G4endl; |
---|
| 76 | G4cerr << G4endl; |
---|
| 77 | G4cerr << "*** G4Exception : " << exceptionCode << G4endl; |
---|
| 78 | G4cerr << " issued by : " << originOfException << G4endl; |
---|
| 79 | G4cerr << description << G4endl; |
---|
| 80 | G4cerr << G4endl << "Severity : "; |
---|
| 81 | switch(severity) |
---|
| 82 | { |
---|
| 83 | case FatalException: |
---|
| 84 | G4cerr << "*** Fatal Exception ***"; |
---|
| 85 | break; |
---|
| 86 | case FatalErrorInArgument: |
---|
| 87 | G4cerr << "*** Fatal Error In Argument ***"; |
---|
| 88 | break; |
---|
| 89 | case RunMustBeAborted: |
---|
| 90 | G4cerr << "*** Run Must Be Aborted ***"; |
---|
| 91 | break; |
---|
| 92 | case EventMustBeAborted: |
---|
| 93 | G4cerr << "*** Event Must Be Aborted ***"; |
---|
| 94 | break; |
---|
| 95 | default: |
---|
| 96 | G4cerr << "*** This is just a warning message. ***"; |
---|
| 97 | toBeAborted = false; |
---|
| 98 | break; |
---|
| 99 | } |
---|
| 100 | G4cerr << G4endl; |
---|
| 101 | } |
---|
| 102 | if(toBeAborted) |
---|
| 103 | { |
---|
| 104 | if(G4StateManager::GetStateManager()->SetNewState(G4State_Abort)) |
---|
| 105 | { |
---|
| 106 | G4cerr << G4endl << "*** G4Exception: Aborting execution ***" << G4endl; |
---|
| 107 | abort(); |
---|
| 108 | } |
---|
| 109 | else |
---|
| 110 | { |
---|
| 111 | G4cerr << G4endl << "*** G4Exception: Abortion suppressed ***" |
---|
| 112 | << G4endl << "*** No guarantee for further execution ***" << G4endl; |
---|
| 113 | } |
---|
| 114 | } |
---|
| 115 | } |
---|
| 116 | |
---|
| 117 | void G4Exception(std::string emessage) |
---|
| 118 | { |
---|
| 119 | G4Exception(emessage.c_str()); |
---|
| 120 | } |
---|
| 121 | |
---|
| 122 | void G4Exception(G4String emessage) |
---|
| 123 | { |
---|
| 124 | G4Exception(emessage.c_str()); |
---|
| 125 | } |
---|