Exemplo n.º 1
0
        public static void ColdCallFileReaderLoop1(string filename)
        {
            var peopleToRing = new ColdCallFileReader();

            try
            {
                peopleToRing.Open(filename);
                for (int i = 0; i < peopleToRing.NPeopleToRing; i++)
                {
                    peopleToRing.ProcessNextPerson();
                }
                Console.WriteLine("All callers proceeded correctly");
            }
            catch (FileNotFoundException)
            {
                Console.WriteLine($"The file {filename} does not exist");
            }
            catch (CodeCallFileFormatException ex)
            {
                Console.WriteLine($"The file {filename} appears to have been corrupted");
                Console.WriteLine($"Details of problem are: {ex.Message}");
                if (ex.InnerException != null)
                {
                    Console.WriteLine($"Inner exception was: {ex.InnerException.Message}");
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine($"Except occurred:\n{ex.Message}");
            }
            finally
            {
                peopleToRing.Dispose();
            }
        }
Exemplo n.º 2
0
        static void DoWork(string fileName)
        {
            var peopleToRing = new ColdCallFileReader();

            try
            {
                peopleToRing.Open(fileName);
                for (int i = 0; i < peopleToRing.NPeopleToRing; i++)
                {
                    peopleToRing.ProcessNextPerson();
                }
                Console.WriteLine("All callers processed correctly");
            }
            catch (FileNotFoundException)
            {
                Console.WriteLine("The file {0} does not exist", fileName);
            }
            catch (ColdCallFileFormatException ex)
            {
                Console.WriteLine("The file {0} appears to have been corrupted",
                                  fileName);
                Console.WriteLine("Details of problem are: {0}", ex.Message);
                if (ex.InnerException != null)
                {
                    Console.WriteLine(
                        "Inner exception was: {0}", ex.InnerException.Message);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Exception occurred:\n" + ex.Message);
            }
            finally
            {
                peopleToRing.Dispose();
            }
        }
Exemplo n.º 3
0
        private static void Do()
        {
            Console.WriteLine("Please type in the name of the file containing the names of the people to be cold called >");
            string fileName = Console.ReadLine();

            ColdCallFileReader peopleToRing = new ColdCallFileReader();

            try
            {
                try
                {
                    peopleToRing.Open(fileName);
                    for (int i = 0; i < peopleToRing.NPeopleToRing; i++)
                    {
                        peopleToRing.PrecessNextPerson();
                    }
                    Console.WriteLine("All callers processed correctly");
                }
                catch (FileNotFoundException)
                {
                    Console.WriteLine("The file {0} does not exist", fileName);
                    throw new Exception("这是测试抛出的异常!");//异常如果抛出来但是外层不catch的话,程序就会直接终止
                }
                catch (ColdCallFileFormatException ex)
                {
                    Console.WriteLine("The file {0} appears to have been corrupted", fileName);
                    Console.WriteLine("Details of  problem are : {0}", ex.Message);
                    if (ex.InnerException != null)
                    {
                        Console.WriteLine("Inner exception was : {0}", ex.InnerException.Message);
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Exception occurred:\n" + ex.Message);
                }
                finally
                {
                    peopleToRing.Dispose();
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("下面抛出来的异常");
                throw ex;
                try
                {
                    string s = "ljla";
                    int i = int.Parse(s);
                }
                catch (Exception ee)
                {
                    throw ee;
                }
            }
            finally
            {
                peopleToRing.Dispose();
            }

            Console.ReadKey();
        }