Interviews - C# Corner

Kapil Gaur
Can multiple catch blocks be executed in a C# program?
By Kapil Gaur in C# onNov 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.

    • 8
  • 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.

    • 4
  • Naveen Bisht
    Nov, 2018 19

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

    • 3
  • Dexent Hamza
    Dec, 2018 25

    Yes

    • 2
  • jubula samal
    Nov, 2018 16

    maximum one catch block will be executed.

    • 2
  • 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.

    • 1
  • Anil Debata
    Mar, 2019 19

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

    • 1
  • Gajendra Jangid
    Mar, 2019 11

    yes we can execute multiple catch blocks...

    • 1
  • Abhishek Shrivastava
    Mar, 2019 9

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

    • 1
  • sushil kumar
    Mar, 2019 6

    No. Only one catch block execute at a time.

    • 1
  • Md Sarfaraj
    Feb, 2019 18

    Yes

    • 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
  • Salman Beg
    Jan, 2019 19

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

    • 1
  • tapan tripathi
    Jan, 2019 8

    A multiple catch block is allowed with different exception filters.

    • 1
  • Amit Prakash
    Jan, 2019 2

    yes

    • 1
  • 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

    • 1
  • 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.

    • 1
  • Abhinav Singh
    Dec, 2018 23

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

    • 1
  • 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

    • 1
  • Sreekanth Reddy
    Nov, 2018 25

    No.

    • 1
  • 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.

    • 1
  • 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.

    • 1
  • 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.

    • 1
  • Rashmiranjan Dalabehera
    Nov, 2018 15

    No, Only one catch block will exeute

    • 1
  • 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.

    • 1
  • Tamil selvan
    Sep, 2019 18

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

    • 0
  • Tamil selvan
    Aug, 2019 12

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

    • 0
  • Bidyasagar Mishra
    Aug, 2019 4

    yes

    • 0
  • 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.

    • 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
  • 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

    • 0
  • 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.

    • 0
  • Guest User
    Apr, 2019 1

    No, It's not possible

    • 0

Most Popular Companies

Most Popular Job Functions

MOST LIKED QUESTIONS