// 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
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.
}
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)
{
//-----------------------------------------------------------------------------
// 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)
{
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?
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)
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;
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;