forked from tejaspundpal/Java-programs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTestThrow2.java
More file actions
29 lines (28 loc) · 789 Bytes
/
Copy pathTestThrow2.java
File metadata and controls
29 lines (28 loc) · 789 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import java.util.*;
class MyException extends Exception{
public MyException(String str){
super(str);
}
}
public class TestThrow2
{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter no : ");
int no = sc.nextInt();
try {
if (no < 10) {
throw new MyException("No is less than 10");
}
else{
System.out.println("no is greater than 10");
}
}
catch(MyException e){
System.out.println(e);
System.out.println("Caught Exception...");
System.out.println(e.getMessage());
}
System.out.println("Rest code....");
}
}