Start networking and exchanging professional insights

Register now or log in to join your professional community.

Follow

Can Multiple Catch Blocks executed in c#?

user-image
Question added by Mohannad Bakbouk , Full Stack Web Developer , Almohtaseb
Date Posted: 2016/10/20
Pratik Jadhav
by Pratik Jadhav , purchase manager , UTICA

Yes. There can be multiple catch blocks. But you have to take while creating them as the one that first matches the exception type is executed first.

Ex.

try

{

}

catch (IOException ex1)

{

    // Code Block 1

}

catch (Exception ex2)

{

    // Code Block 2

}

In above example if exception is IOException then Code Block 1 will be executed otherwise for other exceptions Code Block 2 will be executed.

More Questions Like This

Do you need help in adding the right keywords to your CV? Let our CV writing experts help you.