changeset 6920:2349088c03b4

fix THROW_WITH_FILE_AND_LINE_INFO macro
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 03 Jun 2026 17:50:29 +0200
parents 7a09008728f5
children d602f35554c5 54c24f421d23
files OrthancFramework/Sources/OrthancException.h
diffstat 1 files changed, 12 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/OrthancFramework/Sources/OrthancException.h	Wed Jun 03 16:43:52 2026 +0200
+++ b/OrthancFramework/Sources/OrthancException.h	Wed Jun 03 17:50:29 2026 +0200
@@ -31,12 +31,19 @@
 #include <json/value.h>
 #include <stdint.h>  // For uint16_t
 
+#define THROW_WITH_FILE_AND_LINE_INFO(errorCode) throw OrthancException(errorCode)
+
 #if ORTHANC_ENABLE_LOGGING == 1
-  #define STRINGIFY_LINE_HELPER(line) #line
-  #define STRINGIFY_LINE(line) STRINGIFY_LINE_HELPER(line)
-  #define THROW_WITH_FILE_AND_LINE_INFO(errorCode) throw OrthancException(errorCode, #errorCode " triggered from " __ORTHANC_FILE__ ":" STRINGIFY_LINE(__LINE__))
-#else
-  #define THROW_WITH_FILE_AND_LINE_INFO() throw OrthancException(errorCode)
+// The macro __ORTHANC_FILE__ is only defined for gcc and clang, and if DefineSourceBasenameForTarget is called in CMake
+#  if defined(__ORTHANC_FILE__)
+#    undef THROW_WITH_FILE_AND_LINE_INFO
+#    define ORTHANC_EXCEPTION_STRINGIFY_LINE_HELPER(line) #line
+#    define ORTHANC_EXCEPTION_STRINGIFY_LINE(line) ORTHANC_EXCEPTION_STRINGIFY_LINE_HELPER(line)
+#    define THROW_WITH_FILE_AND_LINE_INFO(errorCode)                    \
+  throw OrthancException(                                               \
+    errorCode, #errorCode " triggered from " __ORTHANC_FILE__ ":"       \
+    ORTHANC_EXCEPTION_STRINGIFY_LINE(__LINE__))
+#  endif
 #endif
 
 namespace Orthanc