internal static void Main()
        {
            // 1st cae
            try
            {
                Person noName = new Person(string.Empty, "Goshev", 31);
                Console.WriteLine(noName);
            }
            catch (ArgumentNullException ex)
            {
                Console.WriteLine("Exception thrown: {0}", ex.Message);
            }
            catch (ArgumentOutOfRangeException ex)
            {
                Console.WriteLine("Exception thrown: {0}", ex.Message);
            }

            // 2nd case
            try
            {
                Person negativeAge = new Person("Stoyan", "Kolev", -1);
                Console.WriteLine(negativeAge);
            }
            catch (ArgumentNullException ex)
            {
                Console.WriteLine("Exception thrown: {0}", ex.Message);
            }
            catch (ArgumentOutOfRangeException ex)
            {
                Console.WriteLine("Exception thrown: {0}", ex.Message);
            }

            // 3rd case
            try
            {
                Person perfect = new Person("Katya", "Marincheva", 52);
                Console.WriteLine(perfect);
            }
            catch (ArgumentNullException ex)
            {
                Console.WriteLine("Exception thrown: {0}", ex.Message);
            }
            catch (ArgumentOutOfRangeException ex)
            {
                Console.WriteLine("Exception thrown: {0}", ex.Message);
            }
        }
Exemplo n.º 2
0
        static void Main()
        {
            try
            {
                Person pesho = new Person("Pesho", "Peshev", 24);
                Person noName = new Person(string.Empty, "Goshev", 33);
                Person noLastName = new Person("Ivan", string.Empty, 35);
                Person negativeAge = new Person("Dragan", "Peshov", -30);
                Person tooOld = new Person("Gosho", "Ivanov", 150);
            }

            catch (ArgumentNullException ex)
            {
                Console.WriteLine($"Exception thrown: {ex.Message}");
            }
            catch (ArgumentOutOfRangeException ex)
            {
                Console.WriteLine($"Exception thrown: {ex.Message}");
            }
        }