I have a method for manually causing the application to crash for testing purposes. It works as supposed to and the custom error page appears just as I want it to. However, I noticed that while the outer exception (i.e. the exception) provides info on location (i.e. Api.Controllers.UtilController.Poof() in UtilController.cs, line 58 on the last line below), the inner one doesn't (stating but Unknown location, while I was led to believe otherwise). The full content of the error message rendered is as follows.
Exception: There are no details but the error code.
GUID: 77ad89f7-7220-43b6-8fe9-d473e18ff07b
See outer text for general info.
Unknown locationException: This is a crash test invoked @ 07:21:15.
See inner exception for details.
Api.Controllers.UtilController.Poof() in UtilController.cs, line 58
I understand that since the inner exception is merely instantiated, not actually thrown, there's no location of its origin. I'd like to alter the location text provided from the inner exception to something custom.
Investigating the contents of the object, I found only two properties seeming to be the likely for that purpose - Source and TargetSite. However, setting those, didn't bring any change in the values (remaining null, despite not being read-only), so I conclude they get overwritten somehow. I also found no field with the string value corresponding to the location anywhere, even after the throw having been invoked.
public ActionResult Poof()
{
string occasion = DateTime.Now.ToString("HH:mm:ss");
string message = "This is a crash test invoked @ " + occasion + "."
+ "\nSee inner exception for details.";
string details = "There are no details but the error code."
+ "\nGUID: " + Guid.NewGuid()
+ "\nSee outer text for general info.";
Exception innerException = new Exception(details);
innerException.Source = "Location as referred below.";
// innerException.TargetSite = new DynamicMethod(...);
Exception exception = new Exception(message, innerException);
throw exception;
}
- Where are those location info strings located in the exception object?
- When/how do they get assigned?
- Can I alter them and if so how?
I've read the docs of the exception page in WebAPI and the general exception object (including the properties such as Source and TargetSite for the InnerException). I feel that I understand the contents but the reality proves otherwise. Effort in research invested, I need help clarifying the three items above.