Manav Pandya
Which Catch block execute when we have multiple catch with try clause
By Manav Pandya in C# on Jan 16 2018
  • Tushar Dikshit
    Jan, 2018 25

    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.

    • 4
  • Gajendra Jangid
    Jan, 2018 29

    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.

    • 3
  • Deependra Kushwah
    Feb, 2018 22

    Depend on the exception raised.

    • 1
  • Sathiya Moorthy
    Feb, 2018 18

    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.

    • 1
  • Munib Butt
    Apr, 2020 28

    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.

    • 0
  • ramila raj
    Nov, 2019 8

    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

    https://youtu.be/sdjR0D5nyqQ

    • 0
  • Bidyasagar Mishra
    Aug, 2019 4

    top to bottom order

    • 0
  • Joy K
    Jun, 2018 7

    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.

    • 0


Most Popular Job Functions


MOST LIKED QUESTIONS