Esempio n. 1
0
 static void generalCatch()
 {
     Car myCar = new Car();
     try
     {                
         Console.WriteLine(@"Attempting to accelerate with ""-10""");
         myCar.AccelerateEx(1030);
     }
     catch(CarOverheatedException coe)
     {
         try
         {
             System.IO.File.OpenText(@"C:\MyLog.txt");
         }
         catch( System.IO.FileNotFoundException fnfe){
             throw new CarOverheatedException(coe.Message, fnfe);
         }
     }
     catch
     {
         Console.WriteLine("Opps something went wrong!");
         
     }
 }
Esempio n. 2
0
        static void driveCar()
        {
            Console.WriteLine("***** Simple Exception Example *****");
            Console.WriteLine("=> Creating a car and stepping on it!");
            Car myCar = new Car("Zippy", 20);
            myCar.CrankTunes(true);
            try
            {
                for (int i = 0; i < 10; i++)
                    myCar.AccelerateEx(10); //myCar.Accelerate(10);
            }
            catch(ArgumentOutOfRangeException aoore)
            {
                Console.WriteLine(aoore.Message);
            }
            catch (CarOverheatedException e)
            {                
                System.Reflection.ParameterInfo[] paramsInfo =  e.TargetSite.GetParameters();
                String str = "";
                foreach ( System.Reflection.ParameterInfo item in paramsInfo)
	            {
                    str += item;
	            }

                Console.WriteLine("\nException source: {0}", e.Source);
                Console.WriteLine(e.TargetSite.MemberType+" -> "+e.TargetSite.DeclaringType + "." + e.TargetSite.Name+"("+str+")");
                Console.WriteLine("\nException message: {0}", e.Message);
                Console.WriteLine("\nException stack:\n {0}", e.StackTrace);
                Console.WriteLine("\nException helpLink: {0}", e.HelpLink);              
            }
        }