Ejemplo n.º 1
0
        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");
        }
Ejemplo n.º 2
0
        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");
        }