Must.Tek
Must.Tek

Reputation: 1370

Is there any way to determine the exception type with using exception message

I am wondering,How can i know the type of exception in .net when i get the exception message from my log file.

For Example: Message: "Error opening the file" (Also exist stacktrace and source info in the log file)

I want to catch this exception in my try catch block.

Upvotes: 0

Views: 123

Answers (1)

InBetween
InBetween

Reputation: 32750

With only the exception message and the stack trace you can not know the exact type of the exception with 100% certainty. This is simply due to the fact that the exception can be thrown with a custom message and not the built in default one.

The stack trace contains no information about the type of the exception either so that doesn't help much.

The best solution is probably modifying the logger so that it registers the exception type. Simply logging exception.ToString() would be enough, the overriden method returns {Type}: {message} {stack trace}. Hard to understand why the logger isn't simply registering that info already.

Upvotes: 1

Related Questions