G4Exception.cc

Go to the documentation of this file.
00001 //
00002 // ********************************************************************
00003 // * License and Disclaimer                                           *
00004 // *                                                                  *
00005 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
00006 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
00007 // * conditions of the Geant4 Software License,  included in the file *
00008 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
00009 // * include a list of copyright holders.                             *
00010 // *                                                                  *
00011 // * Neither the authors of this software system, nor their employing *
00012 // * institutes,nor the agencies providing financial support for this *
00013 // * work  make  any representation or  warranty, express or implied, *
00014 // * regarding  this  software system or assume any liability for its *
00015 // * use.  Please see the license in the file  LICENSE  and URL above *
00016 // * for the full disclaimer and the limitation of liability.         *
00017 // *                                                                  *
00018 // * This  code  implementation is the result of  the  scientific and *
00019 // * technical work of the GEANT4 collaboration.                      *
00020 // * By using,  copying,  modifying or  distributing the software (or *
00021 // * any work based  on the software)  you  agree  to acknowledge its *
00022 // * use  in  resulting  scientific  publications,  and indicate your *
00023 // * acceptance of all terms of the Geant4 Software license.          *
00024 // ********************************************************************
00025 //
00026 //
00027 // $Id$
00028 //
00029 // 
00030 // ----------------------------------------------------------------------
00031 // G4Exception
00032 //
00033 // Global error function prints string to G4cerr (or G4cout in case of
00034 // warning). May abort program according to severity.
00035 // ----------------------------------------------------------------------
00036 
00037 #include "G4ios.hh"
00038 #include "G4String.hh"
00039 #include "G4StateManager.hh"
00040 
00041 void G4Exception(const char* originOfException,
00042                  const char* exceptionCode,
00043                              G4ExceptionSeverity severity,
00044                  const char* description)
00045 {
00046   G4VExceptionHandler* exceptionHandler
00047     = G4StateManager::GetStateManager()->GetExceptionHandler();
00048   G4bool toBeAborted = true;
00049   if(exceptionHandler)
00050   {
00051     toBeAborted = exceptionHandler
00052      ->Notify(originOfException,exceptionCode,severity,description);
00053   }
00054   else
00055   {
00056     static const G4String es_banner
00057       = "\n-------- EEEE ------- G4Exception-START -------- EEEE -------\n";
00058     static const G4String ee_banner
00059       = "\n-------- EEEE -------- G4Exception-END --------- EEEE -------\n";
00060     static const G4String ws_banner
00061       = "\n-------- WWWW ------- G4Exception-START -------- WWWW -------\n";
00062     static const G4String we_banner
00063       = "\n-------- WWWW -------- G4Exception-END --------- WWWW -------\n";
00064     std::ostringstream message;
00065     message << "\n*** ExceptionHandler is not defined ***\n"
00066             << "*** G4Exception : " << exceptionCode << G4endl
00067             << "      issued by : " << originOfException << G4endl
00068             << description << G4endl;
00069     switch(severity)
00070     {
00071      case FatalException:
00072       G4cerr << es_banner << message.str() << "*** Fatal Exception ***"
00073              << ee_banner << G4endl;
00074       break;
00075      case FatalErrorInArgument:
00076       G4cerr << es_banner << message.str() << "*** Fatal Error In Argument ***"
00077              << ee_banner << G4endl;
00078       break;
00079      case RunMustBeAborted:
00080       G4cerr << es_banner << message.str() << "*** Run Must Be Aborted ***"
00081              << ee_banner << G4endl;
00082       break;
00083      case EventMustBeAborted:
00084       G4cerr << es_banner << message.str() << "*** Event Must Be Aborted ***"
00085              << ee_banner << G4endl;
00086       break;
00087      default:
00088       G4cout << ws_banner << message.str()
00089              << "*** This is just a warning message. ***"
00090              << we_banner << G4endl;
00091       toBeAborted = false;
00092       break;
00093     }
00094   }
00095   if(toBeAborted)
00096   {
00097    if(G4StateManager::GetStateManager()->SetNewState(G4State_Abort))
00098    {
00099      G4cerr << G4endl << "*** G4Exception: Aborting execution ***" << G4endl;
00100      abort();
00101    }
00102    else
00103    {
00104      G4cerr << G4endl << "*** G4Exception: Abortion suppressed ***"
00105             << G4endl << "*** No guarantee for further execution ***" << G4endl;
00106    }
00107   }
00108 }
00109 
00110 void G4Exception(const char* originOfException,
00111                  const char* exceptionCode,
00112                  G4ExceptionSeverity severity,
00113                  G4ExceptionDescription & description)
00114 {
00115   G4String des = description.str();
00116   G4Exception(originOfException, exceptionCode, severity, des.c_str());
00117 }
00118 
00119 void G4Exception(const char* originOfException,
00120                  const char* exceptionCode,
00121                  G4ExceptionSeverity severity,
00122                  G4ExceptionDescription & description,
00123                  const char* comments)
00124 {
00125   description << comments << G4endl;
00126   G4Exception(originOfException, exceptionCode, severity, description);
00127 }

Generated on Mon May 27 17:48:13 2013 for Geant4 by  doxygen 1.4.7