Commit 169449c5 authored by Simon Spannagel's avatar Simon Spannagel
Browse files

Merge branch 'fix_abort' into 'master'

G4ExceptionHandler: catch JustWarning-type Exceptions

See merge request allpix-squared/allpix-squared!827
parents ad481187 1da93928
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -10,5 +10,6 @@ random_seed = 0

[GeometryBuilderGeant4]

#PASS (FATAL) [I:GeometryBuilderGeant4] Error during execution of run:\nCaught Geant4 exception GeomVol1002: Overlap with volume already placed
#PASS (WARNING) [I:GeometryBuilderGeant4] Caught Geant4 exception GeomVol1002: Overlap with volume already placed
#FAIL FATAL
#LABEL coverage
+11 −2
Original line number Diff line number Diff line
@@ -13,6 +13,7 @@
#define ALLPIX_GEANT4_EXCEPTIONS_H

#include "core/module/exceptions.h"
#include "core/utils/log.h"

#include <G4VExceptionHandler.hh>

@@ -27,8 +28,16 @@ namespace allpix {
     */
    class G4ExceptionHandler : public G4VExceptionHandler {
    public:
        G4bool Notify(const char*, const char* exceptionCode, G4ExceptionSeverity, const char* description) override {
            throw ModuleError("Caught Geant4 exception " + std::string(exceptionCode) + ": " + std::string(description));
        G4bool Notify(const char*, const char* code, G4ExceptionSeverity severity, const char* description) override {
            std::string message = "Caught Geant4 exception " + std::string(code) + ": " + std::string(description);
            if(severity == G4ExceptionSeverity::JustWarning) {
                LOG(WARNING) << message;
            } else {
                throw ModuleError(message);
            }

            // Continue program execution:
            return false;
        };
    };