+ 8
Can we write multiple catch blocks under single try block?
Multiple catch blocks
3 Answers
+ 3
Yes we can write multiple catch blocks under a single try block.
But when we use multiple catch statements, it is important that exception subclasses come before any of their superclass.
Ans the reason is a catch statement with super class will catch exception of that type plus any of its subclass. The catch statement with sub class exception is a unreachable code which gives error in Java program.
If the order of catch blocks from subclass to parent class is maintained then program will execute normally.
- 1
Yes, but specific exceptions need to be written before the general ones