From d08e013001f0912f6e734b91e45e86ea4f686084 Mon Sep 17 00:00:00 2001
From: Andre Sailer <andre.philippe.sailer@cern.ch>
Date: Thu, 23 Feb 2023 17:05:48 +0100
Subject: [PATCH] DDSim: Userfunction: catch and log exceptions

---
 DDG4/python/DDSim/Helper/Physics.py | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/DDG4/python/DDSim/Helper/Physics.py b/DDG4/python/DDSim/Helper/Physics.py
index 9ca3801dc..db1e82e33 100644
--- a/DDG4/python/DDSim/Helper/Physics.py
+++ b/DDG4/python/DDSim/Helper/Physics.py
@@ -5,8 +5,11 @@ import os
 
 from DDSim.Helper.ConfigHelper import ConfigHelper
 from g4units import mm
+import logging
 import ddsix as six
 
+logger = logging.getLogger(__name__)
+
 
 class Physics(ConfigHelper):
   """Configuration for the PhysicsList"""
@@ -139,7 +142,11 @@ class Physics(ConfigHelper):
       rg.RangeCut = self.rangecut
 
     for func in self._userFunctions:
-      func(kernel)
+      try:
+        func(kernel)
+      except Exception as e:
+        logger.error("Exception in UserFunction: %r", e)
+        raise RuntimeError("Exception in UserFunction: %r" % e)
 
     return seq
 
-- 
GitLab