+ 4

JAVA. Can we have multiple catch blocks after try block?

Can we have multiple catch blocks after try block? Also, does coding a catch block for a parent exception type before the catch block of one of its subclasses causes a compilation error? Thank you for help!

26th Jun 2018, 1:55 AM
DIY Mods
DIY Mods - avatar
3 Réponses
+ 3
Yes you can. After some testing, it seems you can't catch parent exception before child exception and it will give compilation error. You can do the reverse. https://code.sololearn.com/c3dP00YdWptV/?ref=app
26th Jun 2018, 5:11 AM
BlazingMagpie
BlazingMagpie - avatar
+ 2
Yes, you can have multiple catch blocks, and for the second one, I'm pretty sure it doesn't.
26th Jun 2018, 3:22 AM
LunarCoffee
LunarCoffee - avatar
+ 2
thank you very much, guys! I already figured out
26th Jun 2018, 5:15 AM
DIY Mods
DIY Mods - avatar