Practical No. 23, 24 & 25
Practical No. 23, 24 & 25
23, 24 & 25
Program Code: Demonstrates exception handling using try, catch, and
finally block.
class Exception{
int a,b,c;
try{
a = Integer.parseInt(args[0]);
b = Integer.parseInt(args[1]);
c = a/b;
finally {
a = Integer.parseInt(args[0]);
b = Integer.parseInt(args[1]);
c = a+b;
}}}
try {
} catch (Exception e) {
Exercise:
1. The program calculates sum of two numbers inputted as
command-line arguments. When will it give an exception?
class excep{
try {
int n=Integer.parseInt(args[0]);
int n1=Integer.parseInt(args[1]);
int n2=n+n1;
System.out.println("Sum is:"+n2);
catch(NumberFormatException ex){
System.out.println(ex);
} finally {
}}}