Mega Code Archive

 
Categories / C# Tutorial / Language Basics
 

Handle error gracefully and continue

using System;    class MainClass {    public static void Main() {        try {          int j= 0;         int i = 5/j;       }        catch (DivideByZeroException) {          // catch the exception          Console.WriteLine("Can't divide by Zero!");        }    }  } Can't divide by Zero!