Core Java Interview Questions 1 What is the difference between an Abstract class and Interface?


NullPointerException, OutOfMemoryError, DivideByZeroException typically



Download 126,65 Kb.
Pdf ko'rish
bet3/55
Sana01.02.2022
Hajmi126,65 Kb.
#421305
1   2   3   4   5   6   7   8   9   ...   55
Bog'liq
core java interview ques

NullPointerException, OutOfMemoryError, DivideByZeroException typically,
programming errors.
3) What is a user defined exception?
User-defined exceptions may be implemented by
• defining a class to respond to the exception and
• embedding a throw statement in the try block where the exception can occur or
declaring that the method throws the exception (to another method where it is
handled).
The developer can define a new exception by deriving it from the Exception class as follows:
public class MyException extends Exception {
/* class definition of constructors (but NOT the exception handling code) goes here */
public MyException() {
super();
}
public MyException( String errorMessage ) {


super( errorMessage );
}
}
The throw statement is used to signal the occurance of the exception within a try block.
Often, exceptions are instantiated in the same statement in which they are thrown using the
syntax.
throw new MyException("I threw my own exception.")
To handle the exception within the method where it is thrown, a catch statement that
handles MyException, must follow the try block. If the developer does not want to handle
the exception in the method itself, the method must pass the exception using the syntax:
public myMethodName() throws MyException

Download 126,65 Kb.

Do'stlaringiz bilan baham:
1   2   3   4   5   6   7   8   9   ...   55




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