Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            Car myCar = new Car();
            Car yourCar = new Car("Toyota", "Camry");

            myCar.Drive();

            try
            {
                myCar.Accelerator();
            }

            catch (Exception e)
            {
                Console.WriteLine("***ERROR!***");
                Console.WriteLine("Method: " + e.TargetSite);
                Console.WriteLine("Message " + e.Message);
                Console.WriteLine("Source " + e.Source);
                Console.WriteLine("Help link: " + e.HelpLink);
                Console.WriteLine("\n-> Custom Data:");

                if (e.Data != null)
                {
                    foreach (DictionaryEntry de in e.Data)
                        Console.WriteLine("-> " + de.Key + ": " + de.Value);
                }
            }

            myCar.Stop();

            Console.ReadLine();
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            Car myCar = new Car();
            Car yourCar = new Car("Toyota", "Camry");

            myCar.Drive();

            try
            {
                myCar.Accelerator();
            }

            catch (Exception e)
            {
                Console.WriteLine("***ERROR!***");
                Console.WriteLine("Method: " + e.TargetSite); //read only property from Exception class that describes details
                                                              //about the method that threw the exception.

                Console.WriteLine("Message " + e.Message);    //Read only property that returns the description of a given error

                Console.WriteLine("Source " + e.Source);      //This property gets or sets name of the library or object that
                                                              //threw the current exception.

                Console.WriteLine("Help link: " + e.HelpLink); //This property gets or sets a URL to a file or site describing the error
                Console.WriteLine("\n-> Custom Data:");

                if (e.Data != null)
                {
                    foreach (DictionaryEntry de in e.Data)  //read only property that retrieves a collection of key/value pairs that provide
                                                            //additional, programmer defined information about the exception. It is empty by default
                        Console.WriteLine("-> " + de.Key + ": " + de.Value);
                }
            }

            try
            {
                myCar.Stop();
            }

            catch (Exception e)
            {
                Console.WriteLine("Uh-oh, looks like your brakes are failing!");
                Console.WriteLine("***ERROR!***");
                Console.WriteLine("Method: " + e.TargetSite); //read only property from Exception class that describes details
                                                              //about the method that threw the exception.

                Console.WriteLine("Message " + e.Message);    //Read only property that returns the description of a given error

                Console.WriteLine("Source " + e.Source);      //This property gets or sets name of the library or object that
                                                              //threw the current exception.

            }

            Console.ReadLine();
        }
Ejemplo n.º 3
0
        static void Main(string[] args)
        {
            Car myCar = new Car();
            Car yourCar = new Car("Toyota", "Camry");

            myCar.Drive();

            myCar.Accelerator();

            myCar.Stop();

            Console.ReadLine();
        }