— Scott McNealy, Sun Microsystems Chairman, President and ceo



Download 40,57 Mb.
Pdf ko'rish
bet308/555
Sana26.05.2022
Hajmi40,57 Mb.
#609235
1   ...   304   305   306   307   308   309   310   311   ...   555
Bog'liq
Head First Java (Kathy Sierra, Bert Bates) (z-lib.org)

2
1
2
3
The code in the 
catch
block never 
runs.


you are here
4
exception 
handling
327
If you try to cook something, you start by turning on 
the oven. 
If the thing you try is a complete failure, 
you have to turn off the oven.
If the thing you try succeeds,
you have to turn off the oven.
You have to turn off the oven no matter what!
Are you sure 
you want to try 
this?
No matter what, do NOT let 
me forget to turn off the 
oven! Last time I torched half 
the neighborhood. 
Finally: for the things you want 
to do 
no matter what.
A finally block is where you put 
code that must run 
regardless 
of an exception.
try
{

turnOvenOn();


x.bake();
turnOvenOff();
}
catch 
(BakingException ex) 
{
ex.printStackTrace();
turnOvenOff();
}
Without finally, you have to put the 
turnOvenOff() in both the try and the catch 
because you have to turn off the oven no matter 
what. 
A finally block lets you put all your 
important cleanup code in one place instead of 
duplicating it like this:
try
{

turnOvenOn();


x.bake();
}
catch 
(BakingException ex) {
ex.printStackTrace();
}
finally 
{
turnOvenOff();
}
If the try block fails (an exception), 
flow 
control immediately moves to the catch block. 
When the catch block completes, the finally 

Download 40,57 Mb.

Do'stlaringiz bilan baham:
1   ...   304   305   306   307   308   309   310   311   ...   555




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