TAblE 12-2:
Standard Warning Actions
ACTIoN TyPE
dESCRIPTIoN
error
Turns all matching warnings into exceptions, which means the application will
terminate when it encounters the warning unless you provide the required
exception handling.
ignore
Disregards the matching warnings so that the interpreter doesn’t print them
and they don’t affect application execution. Using this action can hide poten-
tially useful warnings from view and make debugging significantly harder.
continues
548592c12.indd 243
2/24/10 12:48:44 PM
www.finebook.ir
244
❘
CHAPTER 12
Debugging ironPython APPlicAtions
ACTIoN TyPE
dESCRIPTIoN
always
Prints the matching warnings, even if the interpreter would normally ignore
it. Using this action displays more information, which could make debugging
easier, but also means that the screen will become clogged with unnecessary
warnings at times.
default
Performs the default warning action of printing the first occurrence of matching
warnings for each location where the interpreter issues the warning. A warn-
ing could appear more than once for each module. For example, it can appear
once in each class within the module.
module
Prints the first occurrence of matching warnings just one time for each module,
even if the interpreter would print the warning more often. Using this action
displays less information than the default action, which means that the console
screen will remain clearer. However, you could miss essential warnings you
need to debug your application.
once
Prints only the first occurrence of matching warnings no matter where the
warning appears. This action is useful when you want to fix each warning
immediately. However, it’ll definitely hide useful debugging information if you
plan to run your application for an extended interval.
It’s important to work with a few warnings to see how filtering works because filters are excep-
tionally important. In order to use warnings, you import the warnings module. Figure 12-1 shows
a typical instance of the default action. Notice that the first time the code issues the
warnings
.warn(“deprecated“, DeprecationWarning)
warning, the interpreter displays a message.
(Don’t worry too much about the specific arguments for the
warnings.warn()
function for right
now; you see them explained in the “Working with Messages” and “Working with Categories”
sections of the chapter.) However, the interpreter ignores the same warning the second time.
If you change the message, however, the interpreter displays another message.
FIgURE 12-1:
The default action displays each message just one time.
Of course, you could always associate a different action with the
warnings
.warn(“deprecated“, DeprecationWarning)
warning. To make this change, you can use the
simplefilter()
function as shown in Figure 12-2. Now when you issue the warning, it appears
every time.
TAblE 12-2
(continued)
548592c12.indd 244
2/24/10 12:48:45 PM
www.finebook.ir
Do'stlaringiz bilan baham: |