Example #1
0
        private static void CheckRange(DateTime date)
        {
            InvalidRangeException <DateTime> dateTimeException = new InvalidRangeException <DateTime>("The argument is out of range",
                                                                                                      new DateTime(1980, 01, 01), new DateTime(2013, 12, 31));

            if (date < new DateTime(1980, 01, 01) || date > new DateTime(2013, 12, 31))
            {
                throw dateTimeException;
            }
        }
Example #2
0
        private static void CheckRange(int number)
        {
            InvalidRangeException <int> intException = new InvalidRangeException <int>
                                                           ("The argument is out of range", 1, 100);

            if (number < 1 || number > 100)
            {
                throw intException;
            }
        }
        static void Main()
        {
            #region Instances initialization
            InvalidRangeException <int> integers = new InvalidRangeException <int>(1, 100);

            DateTime start = DateTime.ParseExact("01.01.1980", "dd.MM.yyyy", CultureInfo.InvariantCulture);
            DateTime end   = DateTime.ParseExact("31.12.2013", "dd.MM.yyyy", CultureInfo.InvariantCulture);
            InvalidRangeException <DateTime> dateTime = new InvalidRangeException <DateTime>(start, end);
            #endregion

            integers.Result();
            dateTime.Result();
        }
Example #4
0
        static void Main(string[] args)
        {
            Exception ex = new InvalidRangeException <int>(10, 20);

            Console.WriteLine(ex.Message);
            try
            {
                int begin  = 1;
                int end    = 100;
                int number = 150;

                if (begin < number && end < number)
                {
                    throw new InvalidRangeException <int>(begin, end);
                }
            }
            catch (InvalidRangeException <int> ire)
            {
                Console.WriteLine(ire.Message);
                Console.WriteLine($"Begin : {ire.Begin} End : {ire.Last} ");
            }
            try
            {
                DateTime begin = new DateTime(1980, 1, 1);
                DateTime last  = new DateTime(2013, 12, 31);
                DateTime date  = new DateTime(2014, 2, 1);

                if (begin < date && date > last)
                {
                    throw new InvalidRangeException <DateTime>(begin, last);
                }
            }
            catch (InvalidRangeException <DateTime> ire)
            {
                Console.WriteLine(ire.Message);
                Console.WriteLine("Begin: {0}, Last: {1}", ire.Begin, ire.Last);
            }
        }
Example #5
0
 static void Main(string[] args)
 {
     var myFirstException  = new InvalidRangeException <int>("Out of range", 1, 100);
     var mySecondException = new InvalidRangeException <DateTime>("Out of range", new DateTime(1980, 1, 1), new DateTime(2013, 12, 31));
 }