C# 0 The Complete Reference


X  that defines a member called  x



Download 4,07 Mb.
Pdf ko'rish
bet459/1096
Sana23.01.2022
Hajmi4,07 Mb.
#402171
1   ...   455   456   457   458   459   460   461   462   ...   1096
Bog'liq
C-Sharp 3 The Complete Reference Herbert Schildt

X

 that defines a member called 



x

 and the 



Add( )

method, which adds the invoking object’s 



x

 to the 


x

 in the object passed as a parameter. In 



Main( )

, two 


X

 objects are created. The first, 



p

, is initialized. The second, 



q

, is not. Instead, it 

is explicitly assigned 

null

. Then 


p.Add( )

 is called with 



q

 as an argument. Because 



q

 does 


not refer to any object, a 

NullReferenceException

 is generated when the attempt is made to 

obtain the value of 

q.x

.

An interesting exception is 



Exception'>StackOverflowException

, which is thrown when the system 

stack is overrun. One situation in which this can happen is when a recursive method runs 

wild. Because the stack is exhausted, a 



StackOverflowException

 can’t be caught by your 

program. Instead, a stack overflow results in the abnormal termination of your program.

Deriving Exception Classes

Although C#’s built-in exceptions handle most common errors, C#’s exception handling 

mechanism is not limited to these errors. In fact, part of the power of C#’s approach to 

exceptions is its ability to handle exceptions that you create. You can use custom exceptions 

to handle errors in your own code. Creating an exception is easy. Just define a class derived 

from 


Exception

. Your derived classes don’t need to actually implement anything—it is their 

existence in the type system that allows you to use them as exceptions.

N

OTE

N

OTE

In the past, custom exceptions were derived from 

ApplicationException

 since this is the 

hierarchy that was originally reserved for application-related exceptions. However, Microsoft 

no longer recommends this. Instead, at the time of this writing, Microsoft recommends deriving 

custom exceptions from 

Exception

. For this reason, this approach is used here.

www.freepdf-books.com




Download 4,07 Mb.

Do'stlaringiz bilan baham:
1   ...   455   456   457   458   459   460   461   462   ...   1096




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