Exemplo n.º 1
0
 public void Accelerate(int delta)
 {
     if (delta < 0)
     {
         throw new
               ArgumentOutOfRangeException("delta", "ускорение не может быть меньше 0!");
     }
     if (carIsDead)
     {
         Console.WriteLine("{0} is out of order...", PetName);
     }
     else
     {
         CurrentSpeed += delta;
         if (CurrentSpeed > MaxSpeed)
         {
             CurrentSpeed = 0;
             carIsDead    = true;
             //throw new Exception(string.Format("{0} привысила скорость!", PetName));
             CarIsDeadException ex = new CarIsDeadException(string.Format("{0} превысил скорость!", PetName), "You have a lead foot", DateTime.Now);
             ex.HelpLink = "http://odnoklasniki.ru";
             //ex.Data.Add("TimeStamp", string.Format("The car exploded at {0}", DateTime.Now));
             //ex.Data.Add("Cause", "You have a lead foot");
             throw ex;
         }
         else
         {
             Console.WriteLine("=> CurrentSpeed = {0}", CurrentSpeed);
         }
     }
 }
Exemplo n.º 2
0
        // Проверить не перегрелся ли автомобиль.
        public void Accelerate(int delta)
        {
            if (delta < 0)
            {
                throw new
                      ArgumentOutOfRangeException("delta", "Speed must be greater than zero!");
            }

            if (carIsDead)
            {
                Console.WriteLine("{0} is out of order. . .", PetName);
            }
            else
            {
                CurrentSpeed += delta;
                if (CurrentSpeed > MaxSpeed)
                {
                    carIsDead    = true;
                    CurrentSpeed = 0;
                    //Создать локальную переменную перед генерацией обьекта Exception.
                    //Что бы можно было обратиться к свойству HelpLink.

                    CarIsDeadException ex =
                        new CarIsDeadException(string.Format("{0} has overheated!", PetName), "You have a lead foot", DateTime.Now);
                    ex.HelpLink = "http://www.CarsRUs.com";
                    throw ex;
                }
                else
                {
                    Console.WriteLine("=> CurrentSpeed = {0}", CurrentSpeed);
                }
            }
        }
Exemplo n.º 3
0
        public void Accelerate(int delta)
        {
            if (delta < 0)
            {
                throw new
                      ArgumentOutOfRangeException("delta", "Speed must be greater than zero!");
            }

            if (carIsDead)
            {
                Console.WriteLine("{0} is out of order...", PetName);
            }
            else
            {
                CurrentSpeed += delta;
                if (CurrentSpeed >= MaxSpeed)
                {
                    carIsDead    = true;
                    CurrentSpeed = 0;
                    CarIsDeadException ex =
                        new CarIsDeadException(string.Format("{0} has overheated!", PetName),
                                               "You have a lead foot", DateTime.Now);
                    ex.HelpLink = "http://www.CarsRU.com";
                    throw ex;
                }
                else
                {
                    Console.WriteLine("=> CurrentSpeed = {0}", CurrentSpeed);
                }
            }
        }
        public void Accelerate(int delta)
        {
            if (delta < 0)
            {
                throw new ArgumentOutOfRangeException("delta", "Speed must be qreater than zero!");
            }
            CarIsDeadException ex = new CarIsDeadException(string.Format("{0} has overheated!", PetName),
                                                           "You have a lead foot", DataTime.Now);

            ex.HelpLink = "http://www.CarsRus.com";
            throw ex;
        }