Professional IronPython



Download 20,35 Mb.
Pdf ko'rish
bet266/453
Sana01.07.2022
Hajmi20,35 Mb.
#723045
1   ...   262   263   264   265   266   267   268   269   ...   453
sys.exc_info()
: Returns a 
tuple
containing three items:


type
: The type of the error, such as 
ZeroDivisionError
. You can find a list of all 
standard exception types in the 
exceptions
module.


value
: The human readable string that defines the error. For example,

ZeroDivisionError
might provide
ZeroDivisionError(‘Attempted to divide by zero.‘,)
as a value.
548592c12.indd 252
2/24/10 12:48:47 PM
www.finebook.ir


Obtaining Error Information
 

 
253


traceback
: An object that describes the stack trace for an exception. Normally, you 
won’t use this information directly unless you truly need to obtain the stack trace 
information, which can prove difficult. If you need stack trace information, consider 
using the 
traceback
module features instead (see the “Using the traceback Module” 
section of this chapter for details).


sys.exc_clear()
: Clears the existing exceptions from the current thread. After you call this 
function, 
sys.exc_info()
returns 
None
for all three elements in the 
tuple
.
The 
sys.exc_info()
function isn’t very hard to use, but you can’t really try it out by executing it 
directly in the IronPython console. You need to place it within a 
try...except
structure instead. 
The following code shows a quick demonstration you can type directly into the console window.
try:
5/0
except:
type, value = sys.exc_info()[:2]
print type
print value
The example uses a simple division by zero to create an exception. As previously noted, you normally 
need just the first two elements of the 
tuple
, which you can obtain using 
sys.exc_info()[:2]
. When 
you execute this code, you see the following output.

Attempted to divide by zero.
Some IronPython 
sys
module functions affect only the interactive thread (which means they’re 
safe to use in multithreaded applications because there is only one interactive thread in any given 
session). You could use these functions to determine the current type, value, and 
traceback
for an 
exception, but only for the interactive session, which means these functions are completely useless 
for your application. In most cases, you avoid using these three functions.

sys.last_traceback()

sys.last_type()


sys.last_value()


You could run into problems when working with some functions in the 
sys
module. For example, 
these three functions are global, which means they aren’t specific to the current thread and are 
therefore, unsafe to use in a multithreaded application.

sys.exc_type()

sys.exc_value()


sys.exc_traceback()


Interestingly enough, these three functions are also listed as deprecated (outdated) in most Python 
implementations (including IronPython). As with all IronPython modules, you also have access to 
548592c12.indd 253
2/24/10 12:48:47 PM
www.finebook.ir



Download 20,35 Mb.

Do'stlaringiz bilan baham:
1   ...   262   263   264   265   266   267   268   269   ...   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