C# 0 The Complete Reference



Download 4,07 Mb.
Pdf ko'rish
bet449/1096
Sana23.01.2022
Hajmi4,07 Mb.
#402171
1   ...   445   446   447   448   449   450   451   452   ...   1096
Bog'liq
C-Sharp 3 The Complete Reference Herbert Schildt

Nesting try Blocks

One


try

 block can be nested within another. An exception generated within the inner 



try

block that is not caught by a 



catch

 associated with that 



try

 is propagated to the outer 



try

 block. 


For example, here the 

IndexOutOfRangeException

 is not caught by the inner 



try

 block, but 

by the outer 

try

:

// Use a nested try block.



using System;

class NestTrys {

  static void Main() {

    // Here, numer is longer than denom.

    int[] numer = { 4, 8, 16, 32, 64, 128, 256, 512 };

    int[] denom = { 2, 0, 4, 4, 0, 8 };

    try { // outer try

      for(int i=0; i < numer.Length; i++) {

        try { // nested try

          Console.WriteLine(numer[i] + " / " +

                             denom[i] + " is " +

                             numer[i]/denom[i]);

        }

        catch (DivideByZeroException) {

          Console.WriteLine("Can't divide by Zero!");

        }

      }

    }


    catch (IndexOutOfRangeException) {

      Console.WriteLine("No matching element found.");

      Console.WriteLine("Fatal error -- program terminated.");

    }


  }

}

The output from the program is shown here:



4 / 2 is 2

Can't divide by Zero!

16 / 4 is 4

www.freepdf-books.com




Download 4,07 Mb.

Do'stlaringiz bilan baham:
1   ...   445   446   447   448   449   450   451   452   ...   1096




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish