Java Program to Rethrowing an Exception

An exception can be rethrown in a catch block. This activity will make the exception be passed to the calling technique. On the off chance that the rethrow activity happens in the fundamental strategy, at that point the exception is passed to the JVM and showed on the console.

Java Program to Rethrowing an Exception
public class ReThrow
{
public static void main(String[] args)
{
try
{
reThrowMethod();
}
catch(ArithmeticException ex)
{
System.out.println("ArithmeticException Re-thrown in reThrowMethod() is
handled here.");
}
}
static void reThrowMethod()
{
try
{
int x=10,y=0;
System.out.println("Quotient : " + (x/y));
}
catch(ArithmeticException e)
{
System.out.println("ArithmeticException caught in reThrowMethod().");
throw e;
}
}
}
OUTPUT
ArithmeticException caught in reThrowMethod().

ArithmeticException Re-thrown in reThrowMethod() is

handled here.


tags : java , java code , java programs , java languages , code , code  hour , java tutorialspoint , tutorialspoint , rethrow , exception , code camp.

Post a Comment

Previous Post Next Post