JL. JL. - 8 months ago 55
C# Question

C# how to generate a proper error quickly for testing purposes

I have some code in my error handler I need to test against a realistic error. How can I generate an error that has a full stack trace and is just as realistic as a runtime error.

I am using a general catch on an exception. So do not need a specific type of exception in this particular case.


object m = null;
string s = m.ToString();

Instant NullReferenceException.