Recent Posts
- NCC Punjab LDC Results 2013 NCCPunjab.com Interview Selected Candidates List
- RGUHS PGSSET Super Speciality 2013 Exam www.logisys.net.in Online Application
- RKCL RS-CIT Results 2013 rkcl.in RSCIT Final Exam May Result 2013
- TNEB Electricity Bills Online Payment tnebnet.org/awp/login Tamilnadu EB Payment System
- Kerala LET 2013 Fee Structure for 2013-14 Engineering College Admission
Discussion Forum
User defined Exceptions in Java with Example – Exception Handling
You can learn about User defined Exceptions in Java with Example Program. In this tutorial you can find user defined exception concept in java Exception Handling with example.
You can learn about User defined Exceptions in Java with Example Program. In this tutorial you can find user defined exception concept in java Exception Handling with example.
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
class MyException extends Exception{
MyException(){}
public String toString(){
return “User created Exception occurred “;
}
}
public class UserExceptionDemo {
public static void main(String[] args) {
try {
BufferedReader br = new BufferedReader(new
InputStreamReader(System.in));
System.out.println(“Enter number”);
int a = Integer.parseInt(br.readLine());
System.out.println(“Enter number”);
int b = Integer.parseInt(br.readLine());
display(a,b);
} catch (MyException e) {
System.out.println(e);
}catch (IOException e) {
System.out.println(e);
}
}
static void display(int x,int y)throws MyException{
if(x>y){
throw new MyException();
}else {
System.out.println(“Exception not occured”);
}
}
}
Result:
i)
Enter number
2
Enter number
3
Exception not occurred
ii)
Enter number
4
Enter number
2
User created Exception occurred
