-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmultiple_catch.java
More file actions
27 lines (22 loc) · 918 Bytes
/
multiple_catch.java
File metadata and controls
27 lines (22 loc) · 918 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
public class multiple_catch {
//A subclass must come before its superclass in a series of catch statements.
//If not, Compile Time error will be generated.
public static void main(String args[])
{
try{
int a=5;
int ar=args.length; //ar=0
int res=a/ar;
}
//Remember,Exception is a superclass and Arithmetic Exception is a subclass of it.
catch(Exception e){
System.out.print("Generic Exception Catch");
}
/*this below exception is never reached because ArithmeticException is a subclass of Exception
catch(ArithmeticException e) --> This is invalid because the exception has already been caught above.
{
System.out.print("This is never reached");
}
To fix above code, just reverse the order of both catch blocks.
*/
}