JL. JL. - 15 days ago 5
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.

Thanks

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

Instant NullReferenceException.