Use of finally block
Use of finally block . This syntax we usually following code to use finally block .
try {
//code
}
catch (){
// code
}
finally {
//code
}
package Exceptions;
import java.io.*;
import java.lang.*;
public class Usefinally {
public static void main(String[] args)
throws IOException {
int x=0,y=0,z=0; double p=0,q=0;
DataInputStream dis=new DataInputStream(System.in);
System.out.println("enter x,y,z values");
try
{
x=Integer.parseInt(dis.readLine());
y=Integer.parseInt(dis.readLine());
z=Integer.parseInt(dis.readLine());
p=x/(y-z);
q=x/(y+z);
}
catch(NumberFormatException e1) {
System.out.println("enter intezer values only"); }
catch(ArithmeticException e2) {
System.out.println("plz check the denominator"); }
finally
{ System.out.println(+x); System.out.println(+y);
System.out.println(+z);
System.out.println(+p);
System.out.println(+q);
}
}
}
program out put
enter x,y,z values
778
667
778
778
667
778
-7.0
0.0
Use of finally block
Reviewed by Mukesh Jha
on
8:17 AM
Rating:
No comments:
Add your comment