[mapguide-commits] r10041 - trunk/MgDev/Common/Foundation/Exception

svn_mapguide at osgeo.org svn_mapguide at osgeo.org
Thu Mar 30 01:26:53 PDT 2023


Author: jng
Date: 2023-03-30 01:26:52 -0700 (Thu, 30 Mar 2023)
New Revision: 10041

Modified:
   trunk/MgDev/Common/Foundation/Exception/Exception.cpp
Log:
#2867: Fixing this problem of explaining why a localized exception message could not be retrieved is actually hard. So in the absence of a workable solution, add a series of debug-only conditional blocks in MgException so that internal developers can stick breakpoints and find out the actual reason for why a localized exception message could not be retrieved.

Fortunately, most of the time the reason for this is either:

 1. The required string bundle was not found at the expected location
 2. A MgException was thrown without the required number of exception message arguments

Breakpoints on the debug-only condition blocks should greatly help with case no 2.

Modified: trunk/MgDev/Common/Foundation/Exception/Exception.cpp
===================================================================
--- trunk/MgDev/Common/Foundation/Exception/Exception.cpp	2023-03-30 08:07:39 UTC (rev 10040)
+++ trunk/MgDev/Common/Foundation/Exception/Exception.cpp	2023-03-30 08:26:52 UTC (rev 10041)
@@ -293,7 +293,32 @@
     }
 
     MG_CATCH_AND_RELEASE()
-
+#if _DEBUG
+    if (nullptr != mgException.p)
+    {
+        // TODO: Ideally we want to be able to capture this exception message and pass it on as the "reason"
+        // for why we're failing to retrieve the original exception message. But my initial attempts at this
+        // resulted in massive recursively nested error messages due to us:
+        //
+        //  a) Currently being in the exception message formatter
+        //  b) Naively trying to call GetExceptionMessage() on this exception which has a very high chance of
+        //     initiating a long cascading recursive chain of similar errors due to argument mismatches on each
+        //     recursive iteration
+        //
+        // This is just a variant of the "what do we do if the exception handler itself throws an exception?"
+        // problem with some extra recursion thrown in.
+        //
+        // In the absence of an actual solution, the next best thing is just to stick a breakpoint in this block
+        // and inspect the contents of the caught mgException in a debugger.
+        //
+        // Fortunately, most of the time the actual reason is we are throwing a MgException somewhere but not
+        // passing the correct amount of arguments for the exception message. So your breakpoint here hits in a
+        // debugger, you know that it's most likely because of this case.
+        //
+        // Or the alternative reason is the obvious mapguide_$locale.res string bundle was not found at the
+        // expected location.
+    }
+#endif
     if (message.empty() && NULL != resources && locale != MgResources::DefaultMessageLocale)
     {
         MG_TRY()
@@ -305,6 +330,12 @@
         message = resources->FormatMessage(resourceStr, arguments);
 
         MG_CATCH_AND_RELEASE()
+#if _DEBUG
+        if (nullptr != mgException.p)
+        {
+            // TODO: See above TODO
+        }
+#endif
     }
 
     if (message.empty() && NULL != resources)



More information about the mapguide-commits mailing list