Its my humble request please edit this
Word File And Paste the Screen Shot of
your Output that you performed in your
Compiler.
Question 1
10 Points
Write a program to handle an exception using try, catch and throw.
CODE : -
Arithmetic Exception
class third
{
public static void main(String[]args)
{
int a=10;
int b=0;
try
{
int c=a/b;
[Link]("C = "+ c);
}
catch(ArithmeticException obj)
{
[Link]("It handle's the Arithmetic Exception");
}
}
}
OUTPUT : -
CODE : -
ArrayIndexOutOfBoundsException
class student
{
public static void main(String[]args) throws Exception
{
int x[] = new int[10];
try
{
[Link](x[11]);
}
catch(ArrayIndexOutOfBoundsException obj1)
{
[Link]("It Handle's "
+ "ArrayIndexOutOfBoundsException");
}
}
}
OUTPUT : -
CODE : -
IOException
import [Link];
class third
{
public static void main(String[]args)
{
try
{
throw new IOException();
}
catch(IOException obj1)
{
[Link]("It Handle's IOException");
}
}
}
OUTPUT : -