class OutOfRange extends Exception{
String message;
OutOfRange(){
message = new String("Please Enter No's between 0 and 100");
}
String toStr(){
return message;
}
}
public class MainCls{
public static void main(String args[]){
int input;
String inputStr;
InputStreamReader isr = new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(isr);
inputStr = br.readLine();
input = Integer.parseInt(inputStr);
try{
if(input < 0 || input > 100)
throw new OutOfRange();
}
catch(OutOfRange e){
System.out.println(e.toStr());
}
//Rest of code...
}
}
Thursday, December 3, 2009
Creating Own exception class in java.
Note: Exception class must be inherited
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment