Grokking The Java Developer Interview: More Than 200 Questions To Crack The Java, Spring, SpringBoot & Hibernate Interview


Question 20: When finally block will not get



Download 7,31 Mb.
Pdf ko'rish
bet10/89
Sana21.04.2022
Hajmi7,31 Mb.
#571320
1   ...   6   7   8   9   10   11   12   13   ...   89
Bog'liq
Grokking-The-Java-Developer-Interview-More-Than-200-Questions-To-Crack-The-Java -Spring -SpringBoot-

Question 20: When finally block will not get
executed


Answer:
when System.exit() is called
when JVM crashes
Question 21: Difference between throw and throws
keyword. And discuss Exception Propagation
Answer:
throw is a keyword which is used to explicitly throw an
exception in the program, inside a function or inside a
block of code, whereas throws is a keyword which is
used with the method signature to declare an exception
which might get thrown by the method while executing
the code
throw keyword is followed by an instance of an
Exception class whereas throws is followed by
Exception class names
You can throw one exception at a time but you can
declare multiple exceptions using throws keyword
Using throw keyword, only unchecked exceptions are
propagated, whereas using throws keyword both
checked and unchecked exceptions can be propagated.
Exception propagation :
An exception is first thrown from the top of the stack and if it is not
caught, it drops down the call stack to the previous method, If not
caught there, the exception again drops down to the previous
method, and so on until they are caught or until they reach the very
bottom of the call stack. This is called exception propagation.


When method m1( ) calls method m2() which calls
method m3(), a stack is formed which gets unfold from
the top, so if method m3() throws an exception and it is
not handled there, it will drop down the call stack to
method m2(), if it is not handled there, it will drop down
the call stack to method m1(), this happens until we
reach the bottom of the stack or until the exception is
caught. This is called Exception Propagation in java.
Example: unchecked exception is thrown and it can be seen from the
call stack that it is propagated
Output:
Example: Here the unchecked exception is handled


Output:
Example: checked exceptions are not propagated down the call

Download 7,31 Mb.

Do'stlaringiz bilan baham:
1   ...   6   7   8   9   10   11   12   13   ...   89




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