Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where does the wording of "Exception of type 'System.Exception'' was thrown" come from?

Tags:

c#

.net

I'm dealing with a complex application which is sometimes produces the following in our log file:

Exception of type 'System.Exception' was thrown

I can track down the cause of the exception but my question is about where the exact wording of the text comes from.

The words Exception of type and was thrown are not in our application, but appear in google searches for all sorts of applications so there must be a system component putting that text together.

It's not the standard ToString() of the exception object, and if I write an app that just throws, the command line output of the app doesn't include that text.

It feels like some standard component is catching the underlying exception and rethrowing it with those words added. If I knew what was doing that it would make it much easier to track down the cause of the underlying issue.

Any ideas?

like image 545
Richard Hunt Avatar asked Oct 29 '25 13:10

Richard Hunt


1 Answers

Exception of type 'System.Exception' was thrown. is the default System.Exception.Message.

dotnet/runtime/blob/master/src/libraries/System.Private.CoreLib/src/System/Exception.cs:

public virtual string Message => _message ?? SR.Format(SR.Exception_WasThrown, GetClassName());

dotnet/runtime/blob/master/src/libraries/System.Private.CoreLib/src/Resources/Strings.resx:

<data name="Exception_WasThrown" xml:space="preserve">
  <value>Exception of type '{0}' was thrown.</value>
</data>
like image 172
dxiv Avatar answered Nov 01 '25 02:11

dxiv



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!