— Scott McNealy, Sun Microsystems Chairman, President and ceo


try { laundry.doLaundry(); } catch(TeeShirtException tex) {



Download 40,57 Mb.
Pdf ko'rish
bet312/555
Sana26.05.2022
Hajmi40,57 Mb.
#609235
1   ...   308   309   310   311   312   313   314   315   ...   555
Bog'liq
Head First Java (Kathy Sierra, Bert Bates) (z-lib.org)

try {
laundry.doLaundry();
} catch(TeeShirtException tex) {
// recovery from TeeShirtException
} catch(LingerieException lex) {
// recovery from LingerieException
} catch(ClothingException cex) {
// recovery from all others
}
TeeShirtExceptions and 
LingerieExceptions need different 
recovery code, so you should use 
different catch blocks.
All other ClothingExceptions 
are caught here.


332
 
chapter 11
The higher up the inheritance tree, the bigger the 
catch ‘basket’. As you move down the inheritance 
tree, toward more and more specialized Exception 
classes, the catch ‘basket’ is smaller. It’s just plain old 
polymorphism. 
A ShirtException catch is big enough to take 
a TeeShirtException or a DressShirtException 
(and any future subclass of anything that extends 
ShirtException). A ClothingException is even bigger 
(i.e. there are more things that can be referenced 
using a ClothingException type). It can take an 
exception of type ClothingException(duh), and 
any ClothingException subclasses: PantsException, 
UniformException, LingerieException, and 
ShirtException. The mother of all catch arguments 
is type 
Exception
; it will catch any exception, 
including runtime (unchecked) exceptions, so you 
probably won’t use it outside of testing.
Multiple catch blocks must be ordered 
from smallest to biggest
UniformException
ClothingException
PantsException
LingerieException
ShirtException
TeeShirtException
DressShirtException
catch(TeeShirtException tex)
catch(ShirtException sex)

Download 40,57 Mb.

Do'stlaringiz bilan baham:
1   ...   308   309   310   311   312   313   314   315   ...   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