Esempio n. 1
0
        public void CatchExceptionMethod()
        {
            try
            {
                MyArray ma = new MyArray();

                // 3) replace second elevent of array by 0

                int[] arr = new int[4] {
                    1, 4, 8, 5
                };
                arr[1] = 0;
                ma.Assign(arr, 4);
            }

            // 8) catch all other exceptions here
            catch (Exception e)
            {
                // 9) print System.Exception properties:
                // HelpLink, Message, Source, StackTrace, TargetSite
                Console.WriteLine(e.HelpLink);
                Console.WriteLine(e.Message);
                Console.WriteLine(e.Source);
                Console.WriteLine(e.StackTrace);
                Console.WriteLine(e.TargetSite);
            }

            // 10) add finally block, print some message
            // explain features of block finally
            finally
            {
                Console.WriteLine("some message");
            }
        }
        public void CatchExceptionMethod()
        {
            try
            {
                MyArray ma = new MyArray();

                // 3) replace second elevent of array by 0

                int[] arr = new int[4] { 1, 4, 8, 5 };
                //int[] arr = new int[4] { 1, 0, 8, 5 };
                ma.Assign(arr, 4);
            }

                // 8) catch all other exceptions here
            catch (Exception ex)
            {
                Console.WriteLine("Main exception: ");

                // 9) print System.Exception properties:
                // HelpLink, Message, Source, StackTrace, TargetSite
                Console.WriteLine("HelpLink: {0}", ex.HelpLink);
                Console.WriteLine("Message: {0}", ex.Message);
                Console.WriteLine("Source: {0}", ex.Source);
                Console.WriteLine("StackTrace: {0}", ex.StackTrace);
                Console.WriteLine("TargetSite: {0}", ex.TargetSite);
            }

            // 10) add finally block, print some message
            // explain features of block finally
            finally
            {
                Console.WriteLine("Finally: here we close connections ");
            }
        }
Esempio n. 3
0
        public void CatchExceptionMethod()
        {
            try
            {
                MyArray ma = new MyArray();

                // 3) replace second elevent of array by 0

                int[] arr = new int[4] {1, 0, 8, 5};
               
                ma.Assign(arr, 4);
            }

                // 8) catch all other exceptions here
            catch (Exception ex)
            {
                Console.WriteLine(ex.HelpLink + "\n" + ex.Message + "\n" + ex.Source + "\n" + ex.StackTrace + "\n" + ex.TargetSite);

                // 9) print System.Exception properties:
                // HelpLink, Message, Source, StackTrace, TargetSite

            }
            finally
            {
                Console.WriteLine("finally block");
            }

            // 10) add finally block, print some message
            // explain features of block finally
           
        }
Esempio n. 4
0
        public void CatchExceptionMethod()
        {
            try
            {
                MyArray ma = new MyArray();

                // 3) replace second elevent of array by 0

                int[] arr = new int[4] {
                    1, 4, 8, 5
                };
                ma.Assign(arr, 4);
                arr[1] = 0;
            }

            // 8) catch all other exceptions here
            catch (Exception ex)
            {
                Console.WriteLine("HelpLink-{0}\n Message-{1}\n Source-{2}\n StackTrace-{3}\n TargetSite-{4}\n", ex.HelpLink, ex.Message, ex.Source, ex.StackTrace, ex.TargetSite);

                // 9) print System.Exception properties:
                // HelpLink, Message, Source, StackTrace, TargetSite
            }
            finally
            {
                Console.WriteLine("Finally");
            }
            // 10) add finally block, print some message
            // explain features of block finally
        }
Esempio n. 5
0
        public void CatchExceptionMethod()
        {
            try
            {
                MyArray ma = new MyArray();

                // 3) replace second elevent of array by 0

                //int[] arr = new int[4] { 1, 4, 8, 5 };
                //ma.Assign(arr, 4);
                int[] ar = new int[4] {
                    1, 9, 8, 5
                };
                //arr[1] = 0;
                //int[] ar = null;
                ma.Assign(ar, 4);
                //Console.WriteLine("{3}", ar[3]);
            }

            // 8) catch all other exceptions here
            catch (System.ArrayTypeMismatchException mm)
            {
                Console.WriteLine(mm.Message);
                Console.WriteLine("This is Type Mismatch Exception");
                // 9) print System.Exception properties:
                // HelpLink, Message, Source, StackTrace, TargetSite
            }
            catch (Exception e)
            {
                e.HelpLink = "www";
                Console.WriteLine(e.HelpLink);
                Console.WriteLine(e.Message);
                Console.WriteLine(e.Source);
                Console.WriteLine(e.StackTrace);
                Console.WriteLine(e.TargetSite);
            }


            // 10) add finally block, print some message
            // explain features of block finally
            finally
            {
                Console.WriteLine("Finally!");
            }
        }
Esempio n. 6
0
        public void CatchExceptionMethod(int[] arr1)
        {
            try
            {
                MyArray ma = new MyArray();

                // 3) replace second elevent of array by 0

                int[] arr = new int[4] {
                    1, 4, 8, 5
                };
                ma.Assign(arr, 4);
                arr[1] = 0;
            }

            // 8) catch all other exceptions here
            catch (Exception q)
            {
                // 9) print System.Exception properties:
                // HelpLink, Message, Source, StackTrace, TargetSite
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine($"HelpLink: {q.HelpLink}");
                Console.WriteLine($"Message: {q.Message}");
                Console.WriteLine($"Source: {q.Source}");
                Console.WriteLine($"StackTrace: {q.StackTrace}");
                Console.WriteLine($"TargetSite: {q.TargetSite}");
            }

            // 10) add finally block, print some message
            // explain features of block finally
            finally
            {
                Console.WriteLine("CatchExceptionMethod finish");
                Console.ReadKey();
            }
        }