ابدأ بالتواصل مع الأشخاص وتبادل معارفك المهنية

أنشئ حسابًا أو سجّل الدخول للانضمام إلى مجتمعك المهني.

متابعة

Can Multiple Catch Blocks executed in c#?

user-image
تم إضافة السؤال من قبل Mohannad Bakbouk , Full Stack Web Developer , Almohtaseb
تاريخ النشر: 2016/10/20
Pratik Jadhav
من قبل 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.

المزيد من الأسئلة المماثلة

هل تحتاج لمساعدة في كتابة سيرة ذاتية تحتوي على الكلمات الدلالية التي يبحث عنها أصحاب العمل؟