Beispiel #1
0
 public void Accelerate(int delta)
 {
     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);
         }
     }
 }
        // See if Car has overheated.
        public void Accelerate(int delta)
        {
            if (carIsDead)
            {
                Console.WriteLine("{0} is out of order...", PetName);
            }
            else
            {
                CurrentSpeed += delta;
                if (CurrentSpeed >= MaxSpeed)
                {
                    carIsDead    = true;
                    CurrentSpeed = 0;

                    // Throw the custom CarIsDeadException.
                    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);
                }
            }
        }
Beispiel #3
0
        public void Accelerate(int delta)
        {
            CarIsDeadException ex = new CarIsDeadException();
            ex.HelpLink = "http://carsrus.com";

            throw ex;
        }
Beispiel #4
0
        // See if Car has overheadred
        public void Accelerate(int delta)
        {
            if (carIsDead)
            {
                Console.WriteLine("{0} is out of order...", PetName);
            }
            else
            {
                CurrentSpeed += delta;
                if (CurrentSpeed > MaxSpeed)
                {
                    CurrentSpeed = 0;
                    carIsDead    = true;

                    // We need to call the HelpLink property,  thus we need
                    // to create a local variable before throwing the Exception object
                    CarIsDeadException ex = new CarIsDeadException(string.Format("{0} has overheated!", PetName), "You have a lead foot", DateTime.Now);
                    ex.HelpLink = "http://www.google.co.uk";
                    throw ex;
                }
                else
                {
                    Console.WriteLine("=> CurrentSpeed = {0}", CurrentSpeed);
                }
            }
        }
Beispiel #5
0
        //gogogogo
        public void Accelerate(int delta)
        {
            if (carIsDead)
            {
                Console.WriteLine("No stupid. I can't go any faster. You already killed {0}", PetName);
            }
            else
            {
                CurrentSpeed += delta;
                if (CurrentSpeed > MaxSpeed)
                {
                    Console.WriteLine("{0} has overheated and blown up, you sorry excuse for a driver", PetName);
                    CurrentSpeed = 0;
                    carIsDead    = true;

                    //throw an exception
                    CarIsDeadException ex = new CarIsDeadException(string.Format("{0} just blew up!", PetName), "You have a lead foot.", DateTime.Now);
                    ex.HelpLink = "www.CarTalk.com";
                    //some stuff in custom data for detail
                    throw ex;
                }
                else
                {
                    Console.WriteLine("Current speed => {0}", CurrentSpeed);
                }
            }
        }
        // Throw an exception if the user speeds up beyond MaxSpeed.
        public void Accelerate(int delta)
        {
            if (carIsDead)
                Console.WriteLine("{0} is out of order...", PetName);
            else
            {
                CurrentSpeed += delta;
                if (CurrentSpeed >= MaxSpeed)
                {
                    carIsDead = true;
                    CurrentSpeed = 0;

                    // We need to call the HelpLink Property, thus we need
                    // to create a local variable before throwing the Exception object.
                    CarIsDeadException ex = new CarIsDeadException(string.Format("{0} has overheated!", PetName),"You have a lead foot", DateTime.Now);
                    ex.HelpLink = "http://www.CarsRUS.com";

                    // Stuff in custom data regading the error.
                    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);
            }
        }
Beispiel #7
0
        public void Accelerate(int delta)
        {
            if (carIsDead)
            {
                Console.WriteLine("{0} is out of order...", PetName);
            }
            else
            {
                CurrentSpeed += delta;
                if (CurrentSpeed > MaxSpeed)
                {
                    Console.WriteLine("{0} has overheated!", PetName);
                    CurrentSpeed = 0;
                    carIsDead    = true;

                    //  使用throw关键字引发异常
                    CarIsDeadException ex = new CarIsDeadException(string.Format("{0} has overheated!", PetName), "You have a lead foot", DateTime.Now);
                    ex.HelpLink = "http:/www.CarsRUs.com";
                    //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);
                }
            }
        }
Beispiel #8
0
        public void Accelerate(int delta)
        {
            if (isCarDead)
            {
                Console.WriteLine("{0} is out of order", PetName);
            }
            else
            {
                CurrentSpeed += delta;
                if (CurrentSpeed > MaxSpeed)
                {
                    CurrentSpeed = 0;
                    isCarDead = true;
                    //Console.WriteLine("{0} has overheated", PetName);
                    //throw new Exception(string.Format("{0} has overheated", PetName));
                    CarIsDeadException ex = new CarIsDeadException(
                        string.Format("{0} has overheated", PetName),
                        "You have a lead foot",DateTime.Now);
                    ex.HelpLink = "http://www.Cars.com";

                   
                    throw ex;

                }
                else
                {
                    Console.WriteLine("=> CurrentSpeed = {0}", CurrentSpeed);
                }
            }
        }
Beispiel #9
0
        public void Accelerate(int delta)
        {
            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 overhated!", PetName),
                                               "You have a lead foot", DateTime.Now);
                    ex.HelpLink = "https://metanit.com";

                    throw ex;
                }
                else
                {
                    Console.WriteLine("=> CurrentSpeed = {0}", CurrentSpeed);
                }
            }
        }
        //Сгенерировать специальное исключение
        public void Accelarete(int delta)
        {
            CarIsDeadException ex = new CarIsDeadException(string.Format("{0} has over!", PetName), "You have a foot", DateTime.Now);

            ex.HelpLink = "http://www.CarsRUs.com";
            throw ex;
        }
Beispiel #11
0
        // See if Car has overheated.
        // This time, throw an exception if the user speeds up beyond MaxSpeed.
        public void Accelerate(int delta)
        {
            if (carIsDead)
            {
                Console.WriteLine("{0} is out of order...", PetName);
            }
            else
            {
                CurrentSpeed += delta;
                if (CurrentSpeed >= MaxSpeed)
                {
                    carIsDead    = true;
                    CurrentSpeed = 0;

                    // We need to call the HelpLink property, thus we need
                    // to create a local variable before throwing the Exception object.
                    CarIsDeadException ex =
                        new CarIsDeadException(string.Format("{0} has overheated!", PetName),
                                               "You have a lead foot", DateTime.Now);
                    ex.HelpLink = "http://www.CarsRUs.com";


                    // Stuff in custom data regarding the error.
                    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);
                }
            }
        }
        public void Accelerate(int delta)
        {
            // Bad param?
            if (delta < 0)
            {
                throw new ArgumentOutOfRangeException("Speed must be greater than zero!");
            }

            if (carIsDead)
            {
                Console.WriteLine("{0} is out of order...", petName);
            }
            else
            {
                currSpeed += delta;
                if (currSpeed >= maxSpeed)
                {
                    carIsDead = true;
                    currSpeed = 0;

                    CarIsDeadException ex =
                        new CarIsDeadException(string.Format("{0} has overheated!", petName));
                    ex.HelpLink = "http://www.CarsRUs.com";

                    // Stuff in extra info about the error.
                    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("=> CurrSpeed = {0}", currSpeed);
                }
            }
        }
Beispiel #13
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)
         {
             CurrentSpeed = 0;
             carIsDead    = true;
             CarIsDeadException ex = new CarIsDeadException(string.Format("{0} has overheated!!!", PetName), "speed", DateTime.Now);
             ex.HelpLink = "https://www.Help.com";
             ex.Data.Add("TimeStamp", string.Format("Time {0}", DateTime.Now));
             ex.Data.Add("Cause", string.Format("speed"));
             throw ex;
         }
         else
         {
             Console.WriteLine("Current speed is {0}", CurrentSpeed);
         }
     }
 }
Beispiel #14
0
        //see if car has overheated
        public void Accelerate(int delta) {
            if (carIsDead)
            {
                Console.WriteLine("{0} is out of order...", PetName);
            }
            else
            {
                CurrentSpeed += delta;
                if (CurrentSpeed >= MaxSpeed)
                {
                    carIsDead = true;
                    CurrentSpeed = 0;

                    //using a simple printed message...
                    //Console.WriteLine("{0} has overheated!", PetName);
                    //using the throw keyword....
                    //throw new Exception(string.Format("{0} has overheated!", PetName));

                    ////help links
                    //Exception ex = new Exception(string.Format("{0} has overheated!",
                    //    PetName));
                    //ex.HelpLink = "http://CarsRUs.com";

                    ////custom data
                    //ex.Data.Add("TimeStamp", string.Format("The car exploded at {0}",
                    //    DateTime.Now));
                    //ex.Data.Add("Cause", "You have a lead foot.");
                    //throw ex;//NOTE wherever you put "throw", any subsequent exceptions you 
                    ////created will not run...IE put this last!

                    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);
                }
            }
        }
Beispiel #15
0
        //Проверить, не перегрелся ли автомобиль (должно генерироваться исключение)
        public void Accelerate(int delta)
        {
            //    if (carIsDead)
            //    {
            //       Console.WriteLine("{0} is out of order...", PetName);
            //   }
            //   else
            //  {
            //  CurrentSpeed += delta;
            //  if ( CurrentSpeed >= MaxSpeed)
            //   {
            //      carIsDead = true;
            //      CurrentSpeed = 0;
            // Console.WriteLine("{0} has overheated!", PetName);
            //carIsDead = true;

            //Создать локальную переменную перед генерацией объекта Exception, чтобы можно было обращаться к свойству HelpLink
            //  Exception ex = new Exception(string.Format("{0}  has overheated!", PetName));
            //    ex.HelpLink = "http://www.CarsRUs.com";

            //Указать специальные данные, касающиеся ошибки
            // ex.Data.Add("TimeStamp", string.Format("The car exploaded at {0}", DateTime.Now));
            // ex.Data.Add("Cause", "You have a lead foot");


            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;


            // Использовать ключевое слово throw для генерации исключения
            //throw new Exception(string.Format("{0} has overheated!", PetName));
            // }
            //  else
            //  {
            //       Console.WriteLine("=> CurrentSpeed = {0}", CurrentSpeed);
            //  }
        }
Beispiel #16
0
 public void Accelerate(int delta)
 {
     if (carIsDead)
     {
         Console.WriteLine("{0} is out of order...", PetName);
     }
     else
     {
         CurrSpeed += delta;
         if (CurrSpeed > MaxSpeed)
         {
             carIsDead = true;
             CurrSpeed = 0;
             CarIsDeadException cEx = new CarIsDeadException(String.Format("{0} has overheated", PetName), "Rules ignorance", DateTime.Now);
             cEx.HelpLink = "www.google.com";
             throw cEx;
         }
         else
         {
             Console.WriteLine("=> Current speed is: {0}", CurrSpeed);
         }
     }
 }
Beispiel #17
0
 public void Accelerate(int delta)
 {
     if (carIsDead)
     {
         Console.WriteLine("{0} is out of order due to an exploded engine...", PetName);
     }
     else
     {
         CurrSpeed += delta;
         if (CurrSpeed >= MaxSpeed)
         {
             CurrSpeed = 0;
             carIsDead = true;
             // Use the throw keyword to raise an exception.
             CarIsDeadException ex = new CarIsDeadException(string.Format("{0} has overheated!", PetName), "You have a lead foot", DateTime.Now);
             ex.HelpLink = "www.google.com";
             throw ex;
         }
         else
         {
             Console.WriteLine("=> CurrSpeed = {0}", CurrSpeed);
         }
     }
 }
Beispiel #18
0
        public void Accelerate(int delta)
        {
            if (carIsDead)
            {
                Console.WriteLine($"{PetName} is out of order");
            }
            else
            {
                CurrentSpeed += delta;
                if (CurrentSpeed > MaxSpeed)
                {
                    CurrentSpeed = 0;
                    carIsDead    = true;

                    CarIsDeadException ex = new CarIsDeadException($"{PetName} was overheated!", "You have a lead foot", DateTime.Now);
                    ex.HelpLink = "http://www.Cars.com";
                    throw ex;
                }
                else
                {
                    Console.WriteLine($"=> Current speed = {CurrentSpeed}.");
                }
            }
        }