Загрузка данных



using System;

namespace LabWork_Exceptions
{
    class Program
    {
        static void Main(string[] args)
        {
            double a = 0;
            double b = 0;

            while (true)
            {
                Console.Write("Введите первое число: ");
                if (double.TryParse(Console.ReadLine(), out a)) break;
                Console.WriteLine("Ошибка ввода.");
            }

            while (true)
            {
                Console.Write("Введите второе число: ");
                if (double.TryParse(Console.ReadLine(), out b)) break;
                Console.WriteLine("Ошибка ввода.");
            }

            Console.WriteLine($"Сумма: {a + b}");
            Console.WriteLine($"Разность: {a - b}");
            Console.WriteLine($"Произведение: {a * b}");

            try
            {
                if (b == 0) throw new DivideByZeroException("Деление на ноль невозможно.");
                double quotient = a / b;
                Console.WriteLine($"Частное: {quotient}");
            }
            catch (Exception ex) when (ex is DivideByZeroException)
            {
                Console.WriteLine($"Ошибка: {ex.Message}");
                Console.WriteLine($"Метод: {System.Reflection.MethodBase.GetCurrentMethod()?.Name}");
            }
            finally
            {
                Console.WriteLine("Завершение операции деления.");
            }

            Console.ReadKey();
        }
    }
}

-----
0.72948 ₽ · /balance_help