Professional IronPython


Debugging the External Module



Download 20,35 Mb.
Pdf ko'rish
bet338/453
Sana01.07.2022
Hajmi20,35 Mb.
#723045
1   ...   334   335   336   337   338   339   340   341   ...   453
Debugging the External Module
 

 
323
unrelated exception. Syntax errors and other problems where the interpreter simply fails can cause the 
developer a lot of woe. For example, your application might have the following syntax error:
# Create a syntax error. 
while True print ‘This is an error!’
This code obviously won’t run. Because of the nature of the error, you might even pass it by while 
looking through your code. The answer to this problem is to create an 
ErrorListener
class like the 
one shown in Listing 15-7.
lISTINg 15-7: 
 Create an ErrorListener to hear script semantic errors
class MyListener : ErrorListener
{
public override void ErrorReported(ScriptSource source,
string message,
SourceSpan span,
int errorCode,
Severity severity)
{
Console.WriteLine(“Script Error {0}: {1}“, errorCode, message);
Console.WriteLine(“Source: {0}“, source.GetCodeLine(span.Start.Line));
Console.WriteLine(“Severity: {0}“, severity.ToString());
}
}
The 
ErrorListener
contains just one method, 
ErrorReported()
. This method can contain any-
thing you need to diagnose errors. The example provides an adequate amount of information for 
most needs. However, you might decide to provide additional information based on the kind of 
script you’re using.
In order to use this approach, you must compile the script before you execute it. The compilation 
process must include the 
ErrorListener
, as shown here.
// Compile the script.
Source.Compile(new MyListener());
When you run the application now, you get some useful information about the syntax error, as 
shown in Figure 15-8.
FIgURE 15-8: 
The ErrorListener provides useful output on syntax errors.
548592c15.indd 323
2/25/10 9:45:57 AM
www.finebook.ir



Download 20,35 Mb.

Do'stlaringiz bilan baham:
1   ...   334   335   336   337   338   339   340   341   ...   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