JL. JL. - 1 year ago 84
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.


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

Instant NullReferenceException.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download