Kapil Gaur
Can multiple catch blocks be executed in a C# program?
By Kapil Gaur in C# on Nov 13 2018
  • sachin hkr
    Nov, 2018 15

    There can be multiple catch blocks, but only the one that first matches the exception type is executed. That means you need to order the catch blocks properly.

    • 11
  • Shaikh Ateeque
    Feb, 2019 7

    Yes, we can write multiple catch blocks in a program , but the child exception (like NullRefernceException, OutOfIndexRangeException etc.) should be written first and the parent exception(i.e. Exception) should be written in last.But only one exception will be executed at a time.

    • 5
  • Naveen Bisht
    Nov, 2018 19

    No, you can use multiple catch blocks but at time only one will execute.

    • 4
  • Vivek Kumar
    Oct, 2019 11

    No, we can have mutliple catch blocks but the one which matches with the exception first will be going to execute.

    • 3
  • Gajendra Jangid
    Mar, 2019 11

    yes we can execute multiple catch blocks...

    • 3
  • tapan tripathi
    Jan, 2019 8

    A multiple catch block is allowed with different exception filters.

    • 3
  • Dexent Hamza
    Dec, 2018 25

    Yes

    • 3
  • jubula samal
    Nov, 2018 16

    maximum one catch block will be executed.

    • 3
  • Ravi Patel
    Feb, 2020 27

    No, we can write multiple catch block but only one is executed at a time.

    • 2
  • Anil Debata
    Mar, 2019 19

    No, multiple catch blocks can't be executed in C#.

    • 2
  • Abhishek Shrivastava
    Mar, 2019 9

    No, we can write multiple catch block but only one is executed at a time.

    • 2
  • sushil kumar
    Mar, 2019 6

    No. Only one catch block execute at a time.

    • 2
  • Md Sarfaraj
    Feb, 2019 18

    Yes

    • 2
  • Salman Beg
    Jan, 2019 19

    We can have multiple catch blocks but only one catch block will be execute at a time.

    • 2
  • kommuri lakshmiah
    Dec, 2018 27

    yes you can....when u want to know which type error coming like null ref,divide by zero,arithmetic like so many error types is there in .net due to multiple blocks code lines will increase so for this better to put Exception, it is the super class for all error types,if you put Exception no need to put multiple blocks.every error will caught by the Exception

    • 2
  • Sneha Reddy
    Dec, 2018 26

    Yes, we can write multiple catch blocks , but the child exception should be written first and the parent exception should be written last.But only one exception will be executed at a time.

    • 2
  • Abhinav Singh
    Dec, 2018 23

    You can have multiple catch block but Only one catch block will be fired.

    • 2
  • Sneha Reddy
    Dec, 2018 20

    Yes, we can write multiple catch blocks but the parent exception should be written last, because once if the compiler enters in to the parent exception catch block then it will not go to the child exceptions

    • 2
  • Alan Moore
    Nov, 2018 24

    I would add that it could be possible for more than one catch block in the program to be executed if one catch block were to throw a new exception which was caught by a different try/catch block.

    • 2
  • Bhanuprasad Mitturi
    Nov, 2018 20

    No. Only one exception block will be executed if there is any exception. finally block will be executed every time , the control enters try block.

    • 2
  • Sreekanth Reddy
    Nov, 2018 17

    We can have multiple catch blocks for single try block. But only one catch concern catch block gets executed for that try block.

    • 2
  • Rashmiranjan Dalabehera
    Nov, 2018 15

    No, Only one catch block will exeute

    • 2
  • Kapil Gaur
    Nov, 2018 13

    No we cannot execute multiple catch blocks for the same try statement. This is because in all cases in case of exception only once the catch statement is executed. After that control goes to finally block if present or code below the try-catch block. You can analyse it in this way like if you have bowled a single ball in Cricket then only one player need to bat that thrown ball. Also while you write multiple catch statements then order in which catch statements are written also matters. Always write child exception first and then parent exceptions. Otherwise if the thrown exception encounters the parent exception catch block then it will never reach child exception catch block.

    • 2
  • Munib Butt
    Apr, 2020 28

    You can write multiple catch blocks in a C# program but only one will be executed at one time after which control will go to the finally block, if it exists.

    • 1
  • Tamil Selvan
    Jan, 2020 24

    At a time only one catch block will executed.

    • 1
  • gowthami budhula
    Dec, 2019 12

    No multiple catch blocks is not executed .what type of exception is occurred that appropriate catch block will be executed.

    • 1
  • Tamil Selvan
    Sep, 2019 18

    One exception block only executed at the time and every time finally block will be excecuted.

    • 1
  • Tamil Selvan
    Aug, 2019 12

    You can have multiple catch blocks, one exception will be executed at a time.

    • 1
  • Saurabh Vasani
    Jul, 2019 26

    No multiple catch block cant be executed when any error occurs in the program only one catch block is execute and then control is transferred to the finally block.

    • 1
  • Tamal Marick
    Apr, 2019 18

    This block is only going to execute when the exception raised in the program. ... If you use multiple catch blocks for the same type of exception, then it will give you a compile-time error because C# does not allow you to use multiple catch block for the same type of exception

    • 1
  • kajal rane
    Apr, 2019 7

    We can Define Multiple Catch Block With Different Type of Exceptions,But Only One Catch Block Is Executed which exception type is matched with type of exception raised by Application.

    • 1
  • Guest User
    Apr, 2019 1

    No, It's not possible

    • 1
  • Hidayat Sawardekar
    Feb, 2019 6

    We can write multiple catch blocks, but at a time only the one exception is executed. If we handle exception and not raise it then next catch will be execute.

    • 1
  • mhamd abd
    Feb, 2019 2

    Yes, we can write multiple catch blocks , but the child exception should be written first and the parent exception should be written last.But only one exception will be executed at a time.

    • 1
  • Md Sarfaraj
    Jan, 2019 25

    Yes

    • 1
  • Amit Prakash
    Jan, 2019 2

    yes

    • 1
  • Sreekanth Reddy
    Nov, 2018 25

    No.

    • 1
  • Tuhin Paul
    Feb, 2023 22

    In a C# program only one catch block will be executed.

    When an exception is thrown, the runtime checks each catch block in order, starting from the top, to see if the exception matches the type of the catch block. Once the first matching catch block is found, it is executed, and the remaining catch blocks are ignored.

    Therefore, it is important to arrange catch blocks in the correct order, with more specific catch blocks first and more general catch blocks last, to ensure that exceptions are caught and handled appropriately. If a more general catch block is placed before a more specific one, it will catch exceptions that should have been handled by the specific catch block, resulting in incorrect program behavior.

    • 0
  • Rakesh Kumar
    Jan, 2023 11

    Hi KAPIL,
    You can check more on below given link.

    https://codeconfig.in/multiple-catch-blocks-in-csharp/

    Hope this will help you.

    • 0
  • Madhura Kesharwani
    Jul, 2021 6

    No. The catch block which matches with the exception first will be going to execute.

    • 0
  • sameer shaikh
    Feb, 2020 2

    In multiple catch block can be execute based on the which type of error match with accordding catch block.``

    • 0
  • Bidyasagar Mishra
    Aug, 2019 4

    yes

    • 0
  • nilesh lokhande
    Jun, 2019 27

    Yes, Multiple catch blocks be executed in c# but at a time only one specific catch block will executed.

    • 0


Most Popular Job Functions


MOST LIKED QUESTIONS