![]() ![]() ![]() | A demonstration of try. | Lecture 0 - slide 8 : 25 Program 4 |
public static void TryCatchDemo(){ int i = 5, r = 0, j = 0; /* Windows: Compile time error. On MONO: Run time error r = i / 0; Console.WriteLine("r is {0}", r); */ try { r = i / j; Console.WriteLine("r is {0}", r); } catch(DivideByZeroException e){ Console.WriteLine("r could not be computed"); } } |