Communiquez avec les autres et partagez vos connaissances professionnelles

Inscrivez-vous ou connectez-vous pour rejoindre votre communauté professionnelle.

Suivre

Can Multiple Catch Blocks executed in c#?

user-image
Question ajoutée par Mohannad Bakbouk , Full Stack Web Developer , Almohtaseb
Date de publication: 2016/10/20
Pratik Jadhav
par Pratik Jadhav , Senior Software Engineer , Crossasyst Technologies

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