I want to throw an exception but with custom message and persist stacktrace too. I've gone through various threads.
catch (Exception ex)
{
throw; // Message is read only but stacktrace persist
throw ex; // Message is readonly and strack trace also blows .. worst!
throw new CustomException("My exception");// Message can be overridden but stacktrace lost
throw new CustomException("My message",ex);// same as above. However if this constructor in exception class calls same constructor of base class then .. see below
}
When last appraoch is used (with custom exception constructor calling base class constructor), output on screen of death is something like:
**The remote server returned an error: (401) Unauthorized.**
[WebException: The remote server returned an error: (401) Unauthorized.]
original stack trace
[NewException: newMessage]
New Stack Trace
Good thing is everything is there on screen. But, on top I want my exception to display i.e. "new message" and not original message.
Hence reconciling my question: HOW can I display on screen of death the original stack trace but with a custom error Message?