Advertisement
Advertisement
//C# Example of exception propagation
using System;
class Exp
{
//Defining a method named Method1() of class Exp
public void Method1()
{
Method2();
}
//Defining a method named Method2() of class Exp
public void Method2()
{
Method3();
}
//Defining a method named Method3() of class Exp
public void Method3()
{
//Local variables
int a = 100, b = 0;
//DivideByZeroException is raised/thrown by the program.
Console.WriteLine(a/b);
//This statement will not be executed.
Console.WriteLine("Hello");
}
//Defining the Main() method of class Exp
public static void Main(String[] arr)
{
//Creating an object of class Exp
Exp ob = new Exp();
//Calling the method Method1() of Exp class
ob.Method1();
}
}
Unhandled Exception: System.DivideByZeroException: Attempted to divide by zero.
at Exp.Method3()
at Exp.Method2()
at Exp.Method1()
at Exp.Main(String[] arr)
Advertisement
Advertisement
Please check our latest addition
C#, PYTHON and DJANGO
Advertisement