Stack Trace

 

using System;

using System.Collections.Generic;

using System.Text;

using System.IO;

using System.Configuration;

using System.Diagnostics;

using System.Reflection;

 

namespace ConsoleApplication1

{

    public class Program

    {

        static void Main(string[] args)

        {

            try

            {

                Console.WriteLine("We're going to divide 10 by 0 and see what happens...");

                Console.WriteLine();

                int i = 10;

                int j = 0;

                int k = i / j; // Error on this line. Control jumps to the catch block.

            }

            //Perform code that deals with the exception or inform the user what occurred.

            catch (Exception e)

            {

                Console.WriteLine("The following error occurred:");

                Console.WriteLine(e.Message);   // Print the error message.

                Console.WriteLine(e.Source);    // Name of application or object that caused the error.

                Console.WriteLine(e.StackTrace); //String that contains the stack trace for this exception.

            }

            finally   //This section is performed regardless of the above processing.

            {

                Console.WriteLine();

                Console.WriteLine("This statement is always printed");

            }

 

        }

 

    }

}