The exception handling is mechanism to handle the runtime errors so that normal
flow(way) of the application can be Continue. Exception is an abnormal condition.
Type of exception
1.Checked Exception
2.Unchecked Exception
3.Error
1. Program
// Find the Output ?
class A
{
public static void main(String[] args)
{
System.out.println(1);
int i = 10 / 0;
System.out.println(1);
}
}
2. Program
// Find the Output ?
class A1
{
public static void main(String[] args)
{
int[] x = {12, 20, 40};
System.out.println(1);
int i = x[9];
System.out.println(1);
}
}
3. Program
// Find the Output ?
class C
{
public static void main(String[] args)
{
System.out.println(1);
test1();
System.out.println(2);
}
static void test1()
{
System.out.println(3);
test2();
System.out.println(4);
}
static void test2()
{
System.out.println(5);
int i = 10 / 0;
System.out.println(6);
}
}
4. Program
// Find the Output ?
class H
{
public static void main(String[] args)
{
System.out.println(1);
test();
System.out.println(2);
}
static void test()
{
System.out.println(3);
test();
System.out.println(4);
}
}
5. Program
// Find the Output ?
class I
{
public static void main(String[] args)
{
System.out.println(1);
int x[] = new int [999999999];
System.out.println(2);
}
}
6. Program
// Find the Output ?
class J
{
public static void main(String[] args)
{
System.out.println(1);
try
{
int i = 10 / 0;
}
catch(ArithmeticException ex)
{
System.out.println(4);
System.out.println(ex);
System.out.println(5);
}
System.out.println(6);
}
}