public static void catchCheckedExceptions() { String s; try { AboutExecptions.doStuff(null); s = "code run successfully"; } catch (ArgumentNullException ex) { s = "exception happended"; } Console.WriteLine("Assert caught exception"); Console.WriteLine(s); Assert.AreEqual(s, "exception happended"); }
public static void useFinally() { String s = ""; try { AboutExecptions.doStuff(null); s = "code run successfully"; } catch (ArgumentNullException ex) { s = "exception happended"; } finally { s += " and it finally run as well"; } Console.WriteLine("Assert used finally"); Console.WriteLine(s); Assert.AreEqual(s, "exception happended and it finally run as well"); }