Call derived ToString on inner exceptions (dotnet/coreclr#24793)
authorDan Moseley <danmose@microsoft.com>
Tue, 28 May 2019 02:34:19 +0000 (19:34 -0700)
committerGitHub <noreply@github.com>
Tue, 28 May 2019 02:34:19 +0000 (19:34 -0700)
* Remove special Appx path and METHOD__EXCEPTION__TO_STRING

* Remove Exception.ToString(bool, bool)

* Remove Exception.InternalToString and callers

* Cache message

Commit migrated from https://github.com/dotnet/coreclr/commit/bb75edbac9c40034b6683c17d86057ee9bf4192d

src/coreclr/src/System.Private.CoreLib/src/System/Exception.CoreCLR.cs
src/coreclr/src/vm/comutilnative.cpp
src/coreclr/src/vm/debughelp.cpp
src/coreclr/src/vm/excep.cpp
src/coreclr/src/vm/mscorlib.h
src/libraries/System.Private.CoreLib/src/System/Exception.cs

index 730b13f..a569e01 100644 (file)
@@ -406,13 +406,6 @@ namespace System
         // See src\inc\corexcep.h's EXCEPTION_COMPLUS definition:
         private const int _COMPlusExceptionCode = unchecked((int)0xe0434352);   // Win32 exception code for COM+ exceptions
 
-        // InternalToString is called by the runtime to get the exception text.
-        internal string InternalToString()
-        {
-            // Get the current stack trace string. 
-            return ToString(true, true);
-        }
-
         internal bool IsTransient
         {
             get
index 5d65956..8d3879e 100644 (file)
@@ -378,38 +378,19 @@ static BSTR GetExceptionDescription(OBJECTREF objException)
     GCPROTECT_BEGIN(MessageString)
     GCPROTECT_BEGIN(objException)
     {
-#ifdef FEATURE_APPX
-        if (AppX::IsAppXProcess())
-        {
-            // In AppX, call Exception.ToString(false, false) which returns a string containing the exception class
-            // name and callstack without file paths/names. This is used for unhandled exception bucketing/analysis.
-            MethodDescCallSite getMessage(METHOD__EXCEPTION__TO_STRING, &objException);
-
-            ARG_SLOT GetMessageArgs[] =
-            {
-                ObjToArgSlot(objException),
-                BoolToArgSlot(false),  // needFileLineInfo
-                BoolToArgSlot(false)   // needMessage
-            };
-            MessageString = getMessage.Call_RetSTRINGREF(GetMessageArgs);
-        }
-        else
-#endif // FEATURE_APPX
-        {
-            // read Exception.Message property
-            MethodDescCallSite getMessage(METHOD__EXCEPTION__GET_MESSAGE, &objException);
-
-            ARG_SLOT GetMessageArgs[] = { ObjToArgSlot(objException)};
-            MessageString = getMessage.Call_RetSTRINGREF(GetMessageArgs);
-
-            // if the message string is empty then use the exception classname.
-            if (MessageString == NULL || MessageString->GetStringLength() == 0) {
-                // call GetClassName
-                MethodDescCallSite getClassName(METHOD__EXCEPTION__GET_CLASS_NAME, &objException);
-                ARG_SLOT GetClassNameArgs[] = { ObjToArgSlot(objException)};
-                MessageString = getClassName.Call_RetSTRINGREF(GetClassNameArgs);
-                _ASSERTE(MessageString != NULL && MessageString->GetStringLength() != 0);
-            }
+        // read Exception.Message property
+        MethodDescCallSite getMessage(METHOD__EXCEPTION__GET_MESSAGE, &objException);
+
+        ARG_SLOT GetMessageArgs[] = { ObjToArgSlot(objException)};
+        MessageString = getMessage.Call_RetSTRINGREF(GetMessageArgs);
+
+        // if the message string is empty then use the exception classname.
+        if (MessageString == NULL || MessageString->GetStringLength() == 0) {
+            // call GetClassName
+            MethodDescCallSite getClassName(METHOD__EXCEPTION__GET_CLASS_NAME, &objException);
+            ARG_SLOT GetClassNameArgs[] = { ObjToArgSlot(objException)};
+            MessageString = getClassName.Call_RetSTRINGREF(GetClassNameArgs);
+            _ASSERTE(MessageString != NULL && MessageString->GetStringLength() != 0);
         }
 
         // Allocate the description BSTR.
index 6f46d0a..0df43d9 100644 (file)
@@ -779,13 +779,13 @@ void PrintException(OBJECTREF pObjectRef)
     }
     else
     {
-        MethodDescCallSite internalToString(METHOD__EXCEPTION__INTERNAL_TO_STRING, &pObjectRef);
+        MethodDescCallSite toString(METHOD__EXCEPTION__TO_STRING, &pObjectRef);
 
         ARG_SLOT arg[1] = {
             ObjToArgSlot(pObjectRef)
         };
 
-        STRINGREF str = internalToString.Call_RetSTRINGREF(arg);
+        STRINGREF str = toString.Call_RetSTRINGREF(arg);
 
         if(str->GetBuffer() != NULL)
         {
index 936d04d..e86fbf9 100644 (file)
@@ -243,7 +243,7 @@ ULONG GetExceptionMessage(OBJECTREF throwable,
 
 //-----------------------------------------------------------------------------
 // Given an object, get the "message" from it.  If the object is an Exception
-//  call Exception.InternalToString, otherwise, call Object.ToString
+//  call Exception.ToString, otherwise, call Object.ToString
 //-----------------------------------------------------------------------------
 void GetExceptionMessage(OBJECTREF throwable, SString &result)
 {
@@ -339,8 +339,8 @@ STRINGREF GetExceptionMessage(OBJECTREF throwable)
     if (throwable == NULL)
         return NULL;
 
-    // Assume we're calling Exception.InternalToString() ...
-    BinderMethodID sigID = METHOD__EXCEPTION__INTERNAL_TO_STRING;
+    // Assume we're calling Exception.ToString() ...
+    BinderMethodID sigID = METHOD__EXCEPTION__TO_STRING;
 
     // ... but if it isn't an exception, call Object.ToString().
     _ASSERTE(IsException(throwable->GetMethodTable()));        // what is the pathway here?
index d328d2a..13ffd95 100644 (file)
@@ -357,8 +357,7 @@ DEFINE_METHOD(EXCEPTION,            GET_CLASS_NAME,         GetClassName,
 DEFINE_PROPERTY(EXCEPTION,          MESSAGE,                Message,                    Str)
 DEFINE_PROPERTY(EXCEPTION,          SOURCE,                 Source,                     Str)
 DEFINE_PROPERTY(EXCEPTION,          HELP_LINK,              HelpLink,                   Str)
-DEFINE_METHOD(EXCEPTION,            INTERNAL_TO_STRING,     InternalToString,           IM_RetStr)
-DEFINE_METHOD(EXCEPTION,            TO_STRING,              ToString,                   IM_Bool_Bool_RetStr)
+DEFINE_METHOD(EXCEPTION,            TO_STRING,              ToString,                   IM_RetStr)
 DEFINE_METHOD(EXCEPTION,            INTERNAL_PRESERVE_STACK_TRACE, InternalPreserveStackTrace, IM_RetVoid)
 #ifdef FEATURE_COMINTEROP
 DEFINE_METHOD(EXCEPTION,            ADD_EXCEPTION_DATA_FOR_RESTRICTED_ERROR_INFO, AddExceptionDataForRestrictedErrorInfo, IM_Str_Str_Str_Obj_Bool_RetVoid)
index 1148cdd..521ade0 100644 (file)
@@ -141,14 +141,9 @@ namespace System
 
         public override string ToString()
         {
-            return ToString(true, true);
-        }
-
-        private string ToString(bool needFileLineInfo, bool needMessage)
-        {
             string s = GetClassName();
 
-            string? message = (needMessage ? Message : null);
+            string? message = Message;
             if (!string.IsNullOrEmpty(message))
             {
                 s += ": " + message;
@@ -156,11 +151,11 @@ namespace System
 
             if (_innerException != null)
             {
-                s = s + " ---> " + _innerException.ToString(needFileLineInfo, needMessage) + Environment.NewLine +
+                s = s + " ---> " + _innerException.ToString() + Environment.NewLine +
                 "   " + SR.Exception_EndOfInnerExceptionStack;
             }
 
-            string? stackTrace = GetStackTrace(needFileLineInfo);
+            string? stackTrace = GetStackTrace(needFileInfo: true);
             if (stackTrace != null)
             {
                 s += Environment.NewLine + stackTrace;