— Scott McNealy, Sun Microsystems Chairman, President and ceo


Which of these do you think



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

Which of these do you think 
might throw an exception that 
the compiler would care about? 
We’re only looking for the 
things that you can’t control in 
your code. We did the first one.
(Because it was the easiest.)
__ connect to a remote server
__ access an array beyond its length
__ display a window on the screen
__ retrieve data from a database
__ see if a text file is where you think it is
__ create a new file
__ read a character from the command-line
Sharpen your pencil
Things you want to do
__________________________________
__________________________________
__________________________________
__________________________________
__________________________________
__________________________________
__________________________________
What might go wrong
the server is down
metacognitive tip
If you’re trying to
learn something
new, 
make that the las
thing you try to
learn 
before going to s
leep. So, once y
ou put this 
book down (assu
ming you can tea
r yourself 
away from it) don
’t read anything 
else more 
challenging than
the back of a Ch
eerios

box. Your brain n
eeds time to pro
cess what 
you’ve read and 
learned. That co
uld take 
a few hours. If yo
u try to shove so
mething 
new in right on to
p of your Java, s
ome of the 
Java might not ‘s
tick.’ 
Of course, this d
oesn’t rule out le
arning 
a physical skill. W
orking on your la
test 
Ballroom KickBo
xing routine 
probably won’t a
ffect your 
Java learning. 
For the best resu
lts, read this 
book (or at least
look at 
the pictures) righ
t before 
going to sleep. 


326
 
chapter 11
try
 {
Foo f = x.doRiskyThing();
int b = f.getNum(); 
}
catch
 
(Exception ex) 
{
System.out.println(“failed”);
}
System.out.println(“We made it!”);
exceptions and 
flow control 
First the try block runs, 
then the code below 
the 
catch runs.
File Edit Window Help RiskAll
%java Tester
We made it!
When you call a risky method, one of two things can hap-
pen. The risky method either succeeds, and the try block 
completes, or the risky method throws an exception back to 
your calling method. 
Flow control in try/catch blocks
If the try 
succeeds
(doRiskyThing() does
not 
throw an exception)
1
try
 {
Foo f = x.doRiskyThing();
int b = f.getNum(); 
}
catch
 
(Exception ex) 
{
System.out.println(“failed”);
}
System.out.println(“We made it!”);
The try block runs, but the 
call to doRiskyThing(
) throws 
an exception, so the rest of 
the try block doesn’t run.
The catch block runs, then 
the method continues on.
File Edit Window Help RiskAll
%java Tester
failed
We made it!
If the try 
fails 
(because doRiskyThing() 
does throw an exception)
The rest of the 
try
block nev-
er runs, which is a Good Thing 
because the rest of the try 
depends on the success of 
the call to doRiskyThing().

Download 40,57 Mb.

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