— Scott McNealy, Sun Microsystems Chairman, President and ceo



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

checked and 
unchecked 
exceptions
1
2


you are here
4
exception 
handling
325
 BULLET POINTS
ß
A method can throw an exception when something fails at runtime.
ß
An exception is always an object of type Exception. (Which, as you 
remember from the polymorphism chapters means the object is from a 
class that has Exception somewhere up its inheritance tree.) 
ß
The compiler does NOT pay attention to exceptions that are of 
type RuntimeException. A RuntimeException does not have to be 
declared or wrapped in a try/catch (although you’re free to do either or 
both of those things)
ß
All Exceptions the compiler cares about are called ‘checked 
exceptions’ which really means compiler-checked exceptions. Only 
RuntimeExceptions are excluded from compiler checking. All other 
exceptions must be acknowledged in your code, according to the 
rules.
ß
A method throws an exception with the keyword 
throw
, followed by 
a new exception object:
throw new NoCaffeineException();
ß
Methods that might throw a checked exception 
must announce it with 

throws Exception 
declaration.
ß
If your code calls a checked-exception-throwing method, it must 
reassure the compiler that precautions have been taken. 
ß
If you’re prepared to handle the exception, wrap the call in a try/catch, 
and put your exception handling/recovery code in the catch block.
ß
If you’re not prepared to handle the exception, you can still make the 
compiler happy by officially ‘ducking’ the exception. We’ll talk about
ducking a little later in this chapter.

Download 40,57 Mb.

Do'stlaringiz bilan baham:
1   ...   302   303   304   305   306   307   308   309   ...   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