User Tools

Site Tools


Force an Error

Just add this little gem to your method and watch the errors fly!

              int i = 1 / int.Parse("0");

VisualStudio (and compilers in general) will try to debug your code on-the-fly, so you can't just tell it to do something illegal, like divide by zero. Sometimes you may have a reason for it though. “Forcing an error” is just a way to make the program try to run an illegal operation. This causes it to “throw an error.” And if an error is thrown, there should be a “catch,” too!

wiki/forceanerror.txt · Last modified: 2019/06/21 01:12 by paul