using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ExceptionHandling
{
class Program
{
static void Main(string[] args)
{
try
{
MethodA();
}
catch (Exception ex) // catches exception thats passed by methodB to methodA to Main
{
Console.WriteLine(ex.StackTrace);
}
Console.Read();
}
static void MethodA()
{
try
{
MethodB();
}
catch (Exception) // this exception was thrown by MethodB
{
throw; //throws catched exception that bubbles up to the method that called this method.
}
}
static void MethodB()
{
try
{
throw new Exception(); //raises exception
}
catch (Exception)
{
throw; //again throws exception but bubbles up to the method that called it.
}
}
}
}