コード例 #1
0
ファイル: ParentClass.cs プロジェクト: emoName/Exception08
        public void NewMethod(Child1 child1)
        {
            //  A(B(C());
            object obj = child1;



            var aa = new { p = 7, ff = "fgrtgr" };

#if DEBUG
            aa = new { p = 4, ff = "Debug" };
#elif RELESE
            aa = new { p = 4, ff = "Relese" };
#endif


            Console.WriteLine(aa.p + aa.ff);


            parentClass2 = obj as ParentClass;

            Console.WriteLine(parentClass2.ss);
        }
コード例 #2
0
        static void Main(string[] args)
        {
            int a = 0, b = 6;

            var parentClass = new ParentClass();


            Child1 child1 = new Child1();

A:
            try
            {
                switch (a)
                {
                case 0:
                    parentClass.NewMethod(child1);
                    break;

                case 1:
                    parentClass.Method3();
                    break;

                case 2:
                    parentClass.Method3();
                    break;

                case 3:
                    parentClass.Method3();
                    break;

                case 4:
                    parentClass.SecondMethod();
                    break;

                default:
                    break;
                }
            }

            catch (Exception e) when(a == 0)
            {
                a++;
                System.Diagnostics.Trace.WriteLine("a>b");

                Debug.WriteLine(e.ToString());
                goto A;
            }
            catch (Exception e) when(a == 1)
            {
                a++;
                System.Diagnostics.Trace.WriteLine("Null Reference Exception a>b ");

                Debug.WriteLine(e.ToString());
                goto A;
            }
            catch (Exception e) when(a == 2)
            {
                a++;
                System.Diagnostics.Trace.WriteLine("a<b");
                Debug.WriteLine(e.ToString());
                goto A;
            }
            catch (Exception e) when(a == 3)
            {
                a++;
                System.Diagnostics.Trace.WriteLine("a<b");
                Debug.WriteLine(e.ToString());
                goto A;
            }
            catch (CustomException e)
            {
                Debug.WriteLine(e.ToString());
            }
            finally
            {
                System.Diagnostics.Trace.WriteLine("Finaly Done");
            }



            Console.ReadLine();
        }