I want to throw an exception, but with a custom message and save the stack. I went through various streams.
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 the last evaluation code is used (with the base class constructor constructor creating the special exception constructor), the output to the death screen looks something like this:
**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
It's good that everything is on the screen. But, at the top, I want my exception to be displayed, that is, a "new message" and not the original message.
So, reconciling my question: HOW can I display the original stack trace on the death screen, but with a custom error message?
source share