— Scott McNealy, Sun Microsystems Chairman, President and ceo



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

ClothingException'>Exception
IOException
1
public void doLaundry()
throws ClothingException
{
Declaring a ClothingException lets you throw 
any subclass of ClothingException . That means 
doLaundry() can throw a PantsException
LingerieException, TeeShirtException, and 
DressShirtException without explicitly declaring them 
individually.
You can CATCH exceptions using a 
supertype of the exception thrown.
2
try {
laundry.doLaundry();
} catch(ClothingException
cex) {
// recovery code
}
try {
laundry.doLaundry();
} catch(ShirtException sex) {
// recovery code
}
can catch only 
TeeShirtException 
and 
DressShirtException 
can catch any 
ClothingException 
subclass
ClothingException
PantsException
LingerieException
ShirtException
TeeShirtException
DressShirtException
polymorphic 
exceptions 


you are here
4
exception 
handling
331
You could write your exception-handling code so that 
you specify only one catch block, using the supertype 
Exception in the catch clause, so that you’ll be able to 
catch any exception that might be thrown.
Just because you CAN catch everything 
with one big super polymorphic catch, 
doesn’t always mean you SHOULD.
try {
laundry.doLaundry();
} catch(Exception ex) {
// recovery code...
}
Recovery from WHAT
? This catch block will 
catch ANY and all exceptions, so you won’t 
automatically know what went wrong. 
For example, if your code deals with (or recovers 
from) a TeeShirtException differently than it handles a 
LingerieException, write a catch block for each. But if you 
treat all other types of ClothingException in the same way, 
then add a ClothingException catch to handle the rest.
Write a different catch block for each 
exception that you need to handle 
uniquely.

Download 40,57 Mb.

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