Throw statement :
The throw statement is used to explicitly raise the
exception .
The general form is
throw
new Exceptiontype();
PROGRAM
class ExceptionDem7
{
public
static void main(String args[ ])
{
try
{
int
a,b;
if(args.length!=2)
throw new
ArrayIndexOutOfBoundsException();
a=Integer.parseInt(args[0]);
b=Integer.parseInt(args[1]);
int c;
if(b==0)
throw
new ArithmeticException();
c=a/b;
System.out.println("Result
= "+c);
}
catch(Exception
e)
{
System.out.println("Exception
Is :"+e);
}
}
}
Comments
Post a Comment