Professional IronPython


Interacting with .NET Framework Elements



Download 20,35 Mb.
Pdf ko'rish
bet149/453
Sana01.07.2022
Hajmi20,35 Mb.
#723045
1   ...   145   146   147   148   149   150   151   152   ...   453
Interacting with .NET Framework Elements
 

 
133
ThisException = System.OperationCanceledException(‘The User Said No!’)
# Ask the user a question.
try:
Answer = raw_input(‘Do you want to continue? (Y/N)‘)
# Check the response.
if Answer.upper() == ‘Y’:
print ‘Great!’
else:
raise(ThisException)
except SystemError as (SysErr):
print ‘\nMessage:’, SysErr.message
print ‘\nClass:’, SysErr.clsException.GetType()
print ‘\nClass, Message, and Stack Trace:’, SysErr.clsException
# Pause after the debug session.
raw_input(‘Press any key to continue...’)
The example starts out as most do in the chapter by making the appropriate references and import-
ing the correct modules and assemblies. The first bit of code creates an exception, 
ThisException

by calling the 
System.OperationCanceledException()
constructor. You can embed previous 
exceptions in the current exception by using the correct constructor, but the example uses just one 
level to keep things simple.
The code then asks the user a simple question. If the user answers N, the code raises an excep-
tion and then catches it as a 
SystemError
. Notice that this exception handler provides a means 
of accessing the error through 
SysErr
. The easiest way to obtain the error message is through the 
SysErr.message
.
Of course, you’ll probably want more information. All of the .NET errors will appear as the 
SystemError
type. Consequently, you need to consider how to detect the proper error class in 
your IronPython code. The 
SysErr.clsException.GetType()
provides the answer. You can also 
display a complex message by displaying the 
SysErr.clsException
attribute. Figure 7-13 shows 
the output from this example.
FIguRE 7-13: 
Use SysErr.clsException.GetType () to obtain an error class. 
548592c07.indd 133
2/25/10 9:44:30 AM
www.finebook.ir



Download 20,35 Mb.

Do'stlaringiz bilan baham:
1   ...   145   146   147   148   149   150   151   152   ...   453




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