A)
Note:
->Identify doubtful code in the application that may cause exception, placing it in try block and writing corresponding catch block(s) is nothing but Exception handling.
//withhandling.java
class withhandling {
public static void main(String[] args) {
int n,d,q=1;
System.out.println("program is started :");
n=Integer.parseInt(args[0]);
d=Integer.parseInt(args[1]);
try
{q=n/d;
System.out.println("the result of division is :"+q);
}
catch(ArithmeticException e)
{
System.out.println("division failed second input value shouldn't be zero");
}
System.out.println("the application completely executed");
}
}
Run :
java withhandling 10 0
->whenever enter 10 0 , then the arithmetic exception is raised by JVM and creates that object and throws that. That object is catched by catch block.
Comments
Post a Comment