The first one which matches the type of exception thrown. Normally we go from most specific to most generic. The last one is usally simply an “Exception” type and hence if the exception is not caught by any of the specific types it gets caught with the final generic type.
Interviews8 answers
Which Catch block execute when we have multiple catch with try clause
8 Answers
Munib ButtPosted Apr 28, 2020, 10:03 AM EDT
once the exception occur the appropiriate catch will execute if it is not there means the base catch block will execute
know more about this question refer
ramila rajPosted Nov 7, 2019, 7:34 PM EST
top to bottom order
Bidyasagar MishraPosted Aug 4, 2019, 4:32 PM EDT
If there is a catch block of the exception raised in try block, then respective catch block is executed otherwise the general exception that holds all the exceptions will be executed.
Joy KPosted Jun 7, 2018, 1:58 PM EDT
Depend on the exception raised.
Deependra KushwahPosted Feb 22, 2018, 1:38 AM EST
Compiler will look for a related catch block, if it is not found, then it will throw an unhanded exception. For instance, if arithmetic exception occurs in the try block, then it will look for the Arithmetic catch (ArithmeticException e) block or the general exception block, if both are not found, it will throw an unhandled exception for sure.
Sathiya MoorthyPosted Feb 17, 2018, 9:06 PM EST
In this case, the order of the catch clauses is important because the catch clauses are examined in order. Catch the more specific exceptions before the less specific ones. The compiler produces an error if you order your catch blocks so that a later block can never be reached.
Gajendra JangidPosted Jan 28, 2018, 8:00 PM EST
IF you have catch blocks for specific types and that type of exception occurs, it will execute.
Example catch(NullReferenceException e)()
so if null reference exception occurs it will go here.
----------------------------------------------------------------------------------------------
Also ordering is very important in multiple catch blocks.
Put specific catch blocks first then generic.
For example catch(Exception e) will catch all type of exceptions, so put it last.
Tushar DikshitPosted Jan 25, 2018, 10:10 AM EST






