Oct

19

import java.io.*;
class Ex{
public static void main(String args[]){
Console c=System.console();
String snum1=c.readLine(“1st No: “);
String snum2=c.readLine(“2nd No: “);
try{
int n1=Integer.parseInt(snum1);
int n2=Integer.parseInt(snum2);
System.out.println(n1+n2);
System.out.println(n1-n2);
System.out.println(n1*n2);
System.out.println(n1/n2);
}
catch(ArithmeticException e){
System.out.println(e);
}
finally{
System.out.println(“Finally Called”);
}
System.out.println(“Exit from main”);
}
}

————————————————————————————–

import java.io.*;
class Ex1{
public static void main(String args[]){
Console c=System.console();
String snum1=c.readLine(“1st No: “);
String snum2=c.readLine(“2nd No: “);
try{
int n1=Integer.parseInt(snum1);
int n2=Integer.parseInt(snum2);
System.out.println(n1+n2);
System.out.println(n1-n2);
System.out.println(n1*n2);
System.out.println(n1/n2);
}
catch(Exception e){  // it will generate compile error
System.out.println(e);
}
catch(ArithmeticException e){
System.out.println(e);
}
catch(NullPointerException e){
System.out.println(e);
}

finally{
System.out.println(“Finally Called”);
}
System.out.println(“Exit from main”);
}
}

————————————————————————————-

import java.io.*;
class Ex2{
public static void main(String args[]){
Console c=System.console();
String snum1=c.readLine(“1st No: “);
String snum2=c.readLine(“2nd No: “);
int n1=Integer.parseInt(snum1);
int n2=Integer.parseInt(snum2);
if(n1<=5){
//throw new NumberFormatException(“Explict Thrown <=5”);
try{
throw new InterruptedException(“Explict Intruupt”);
}catch(InterruptedException i){
}
}
System.out.println(n1+n2);
}
}

——————————————————————————————-

import java.io.*;
class Ex3{
public static void main(String args[])throws InterruptedException{
Console c=System.console();
String snum1=c.readLine(“1st No: “);
String snum2=c.readLine(“2nd No: “);
int n1=Integer.parseInt(snum1);
int n2=Integer.parseInt(snum2);
if(n1<=5){
//throw new NumberFormatException(“Explict Thrown <=5”);
throw new InterruptedException(“Explict Intruupt”);
}
System.out.println(n1+n2);
}
}

——————————————————————————————————

import java.io.*;
class Ex4{
public static void main(String args[])throws MyExcep{
System.out.println(“Thows Exception”);
int i=0;
if(i==0)
throw new MyExcep(“This exception is created by programmer”);
System.out.println(“Exit from main”);
}
}
class MyExcep extends Exception{
MyExcep(String s){
super(s);
}
}

——————————————————————————————————-

import java.io.*;
class Ex5{
public static void main(String args[]){
System.out.println(“Thows Exception”);
int i=0;
try{
if(i==0)
throw new MyExcep(“This exception is created by programmer”);
}catch(MyExcep e){
}
System.out.println(“Exit from main”);
}
}
class MyExcep extends Exception{
MyExcep(String s){
super(s);
}
}

—————————————————————————————————-

import java.io.*;
class Ex6{
public static void main(String args[]){
System.out.println(“Thows Exception”);
Ex6 e6=new Ex6();
try{
e6.m1();
}catch(MyExcep e){
}
System.out.println(“Exit from main”);
}
void m1()throws MyExcep{
int i=0;
if(i==0)
throw new MyExcep(“This exception is created by programmer”);

}
}
class MyExcep extends Exception{
MyExcep(String s){
super(s);
}
}

————————————————————————————————————-

import java.io.*;
class Ex7{
public static void main(String args[]){
}
void m1()throws MyExcep{
}
void m2() throws Exception{
}
void m3() throws NumberFormatException{
}
}
class Ex extends Ex7{
void m1() throws NumberFormatException{
}
void m3()throws NumberFormatException,NullPointerException{
}
}
class MyExcep extends Exception{
MyExcep(String s){
super(s);
}
}

 

 


Leave a Reply