changeset 6953:9832a716c687

PluginException.h: enable throwing from plugins with filename and line number
author Alain Mazy <am@orthanc.team>
date Wed, 17 Jun 2026 16:28:24 +0200
parents 94af24a493de
children cd1a8195a03c
files OrthancServer/Plugins/Samples/Common/OrthancPluginException.h
diffstat 1 files changed, 19 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/OrthancServer/Plugins/Samples/Common/OrthancPluginException.h	Wed Jun 17 16:03:55 2026 +0200
+++ b/OrthancServer/Plugins/Samples/Common/OrthancPluginException.h	Wed Jun 17 16:28:24 2026 +0200
@@ -40,14 +40,28 @@
 #  define ORTHANC_PLUGINS_GET_ERROR_CODE(code)  ::OrthancPluginErrorCode_ ## code
 #endif
 
+#if HAS_ORTHANC_EXCEPTION == 1 && defined(__ORTHANC_FILE__)   // the OrthancException accepts a detail argument -> add the file and line number
+#  define PLUGIN_ORTHANC_EXCEPTION_STRINGIFY_LINE_HELPER(line) #line
+#  define PLUGIN_ORTHANC_EXCEPTION_STRINGIFY_LINE(line) PLUGIN_ORTHANC_EXCEPTION_STRINGIFY_LINE_HELPER(line)
+#  define PLUGIN_THROW_WITH_FILE_AND_LINE_INFO(errorCode)                    \
+    throw ::Orthanc::OrthancException(                                               \
+      errorCode, #errorCode " triggered from " __ORTHANC_FILE__ ":"       \
+      PLUGIN_ORTHANC_EXCEPTION_STRINGIFY_LINE(__LINE__))
 
-#define ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(code)                   \
-  throw ORTHANC_PLUGINS_EXCEPTION_CLASS(static_cast<ORTHANC_PLUGINS_ERROR_ENUMERATION>(code));
+#  define ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(code)                   \
+  PLUGIN_THROW_WITH_FILE_AND_LINE_INFO(static_cast<ORTHANC_PLUGINS_ERROR_ENUMERATION>(code))    
+
+#  define ORTHANC_PLUGINS_THROW_EXCEPTION(code)                           \
+  PLUGIN_THROW_WITH_FILE_AND_LINE_INFO(ORTHANC_PLUGINS_GET_ERROR_CODE(code))    
+
+#else // the PluginException does not accept a detail argument
+#  define ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(code)                   \
+    throw ORTHANC_PLUGINS_EXCEPTION_CLASS(static_cast<ORTHANC_PLUGINS_ERROR_ENUMERATION>(code));
 
 
-#define ORTHANC_PLUGINS_THROW_EXCEPTION(code)                           \
-  throw ORTHANC_PLUGINS_EXCEPTION_CLASS(ORTHANC_PLUGINS_GET_ERROR_CODE(code));
-                                                  
+#  define ORTHANC_PLUGINS_THROW_EXCEPTION(code)                           \
+    throw ORTHANC_PLUGINS_EXCEPTION_CLASS(ORTHANC_PLUGINS_GET_ERROR_CODE(code));
+#endif                                                  
 
 #define ORTHANC_PLUGINS_CHECK_ERROR(code)                           \
   if (code != ORTHANC_PLUGINS_GET_ERROR_CODE(Success))              \