— Scott McNealy, Sun Microsystems Chairman, President and ceo



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

334
 
chapter 11
polymorphic puzzle
BiffEx
FooEx
BarEx
try {
x.doRisky();
} catch(AlphaEx a) {
// recovery from AlphaEx
} catch(BetaEx b) {
// recovery from BetaEx
} catch(GammaEx c) {
// recovery from GammaEx
} catch(DeltaEx d) {
// recovery from DeltaEx
}
BazEx
BoinkEx
Assume the try/catch block here is legally coded. Your task is to draw 
two different class diagrams that can accurately refl ect the Exception 
classes. In other words, what class inheritance structures would make the 
try/catch blocks in the sample code legal?
Your task is to create two different legal try / catch structures (similar to 
the one above left), to accurately represent the class diagram shown on 
the left. Assume ALL of these exceptions might be thrown by the method 
with the try block.
Sharpen your pencil


you are here
4
exception 
handling
335
The art of ducking an exception
When you don’t want to handle 
an exception...
If you don’t want to handle an 
exception, you can 
duck
it by 
declaring 
it.
When you call a risky method, the compiler 
needs you to acknowledge it. Most of the time, 
that means wrapping the risky call in a try/
catch. But you have another alternative, simply 
duck it and let the method that called you catch 
the exception. 
It’s easy—all you have to do is declare that 
you throw the exceptions. Even though, 
technically, you aren’t the one doing the 
throwing, it doesn’t matter. You’re still the one 
letting the exception whiz right on by. 
But if you duck an exception, then you don’t 
have a try/catch, so what happens when the 
risky method (doLaundry()) 
does throw the 
exception? 
When a method throws an exception, that 
method is popped off the stack immediately, 
and the exception is thrown to the next 
method down the stack—the caller. But if the 
caller is a ducker, then there’s no catch for it so 
the caller pops off the stack immediately, and 
the exception is thrown to the next method 
and so on... where does it end? You’ll see a 
little later.
just duck it
What the...?
There is NO way I’m 
catching that thing. I’m gettin’ 
out of the way-- somebody 
behind me can handle it.

Download 40,57 Mb.

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