Richard Pianka
Richard Pianka

Reputation: 3356

Parse exception string

Is there any way to parse an Exception's ToString() output back into an Exception object? Imagine I have this string:

System.IndexOutOfRangeException: Index was outside the bounds of the array.  
    at Sandbox.Program.Main(String[] args) in C:\Development\Personal\Sandbox\Program.cs:line 12

I'd like to pass that value to a method and have it return an Exception object where I can then pull out the name, message, stack trace etc. Is this possible in .NET, or is there another library/project that can do this?

Upvotes: 2

Views: 1506

Answers (1)

Mrchief
Mrchief

Reputation: 76208

It is not possible just from the string (or at least from the minimal string you've shown).

Best is to have a global error handler that can catch uncaught exceptions.

If you're in ASP.Net, Server.GetLastError() can help you retrieve the exception object.

Upvotes: 2

Related Questions