Using try and catch ,the default exception handler provide the Java Runtime System is used for debugging.You will usually want to handle an exception yourself.To guard against and handle a runtime error simply encloses the code that you want to monitor inside the try block.Immediately following the try block inside a catch clause that specify the exception type that you want to wish to catch.The following program include try block and catch clause which process Arithmetic Exception.
class A
{
int d,a;
try
{
d=0;
a=42;
a=a/d;
system.out.println("This will not be permitted");
}
catch(Exception e)
{
System.out.println("division by 0is not possible !");
}
}
OUTPUT
division by 0 is not possible.
class A
{
int d,a;
try
{
d=0;
a=42;
a=a/d;
system.out.println("This will not be permitted");
}
catch(Exception e)
{
System.out.println("division by 0is not possible !");
}
}
OUTPUT
division by 0 is not possible.
No comments:
Post a Comment