DEV Community

Firdavs Mukhsimov
Firdavs Mukhsimov

Posted on

Exception Handling

a)try, catch, finally bloklari qanday ishlaydi?

try, catch, va finally bloklari Java va 
boshqa ko‘plab dasturlash tillarida xatolarni
boshqarish uchun ishlatiladi. Ularning qanday
 ishlashini quyida batafsil ko‘rsataman:
Enter fullscreen mode Exit fullscreen mode

Quyidagi kod nima qiladi?

try
int[] numbers = { 1, 2, 3 };
Console. WriteLine (numbers [10]);
catch (IndexOutOfRangeException e)
Console. WriteLine("Error: " + e.Message) ;
finally
Console. WriteLine("Finally block executed.");


Javob:try bloki ichida, numbers[10] ifodasi xatoga 
olib keladi, chunki numbers massivining 
faqat 0, 1 va 2 indekslari mavjud.

Enter fullscreen mode Exit fullscreen mode

Top comments (0)