Visit our site: Vist and Get Free Gifts

Learn To Build: RethrowingExceptions in C#

Visit our site: Vist and Get Free Gifts

Visit our site: Vist and Get Free Gifts

Wednesday, February 12, 2014

RethrowingExceptions in C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace RethrowingExceptions
{
    class Program
    {
        static void DoSomeMath()
        {
            int x = 10, y = 0;
            int result;

            try
            {
                result = x / y;
                Console.WriteLine("Result is {0}", result);
            }
            catch
            {
                Console.WriteLine("Error in DoSomeMath()");
                throw new ArithmeticException();
            }
        }

        static void Main(string[] args)
        {
            try
            {
                DoSomeMath();
            }
            catch (ArithmeticException e)
            {
                Console.WriteLine("Hmm, there was an error in there, be careful!");
            }

            Console.ReadLine();
        }
    }
}

Labels:

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home