242
❘
CHAPTER 12
Debugging ironPython APPlicAtions
two debuggers: the Common Language Runtime (CLR) debugger and the Visual Studio debugger.
Neither of these solutions is perfect and you might have to combine them to locate the precise source
of the bug in your application.
Easy debugging actually begins with good exception handling. When you understand the potential
sources of bugs in your application, you can add exceptions and exception handlers to alert you to
these conditions. A sudden rise in exceptions can signal a change in environment, new threats to your
application, or modifications in user patterns. IronPython tends to force you to create robust error-
handling routines, which really isn’t a bad feature to add to an application.
UNdERSTANdINg IRoNPyTHoN WARNINgS
Warnings are simply indicators that something could be wrong with your application or might not
work under all conditions. For example, if you use a deprecated (outdated) function, you might later
find that the application refuses to work on all machines. You can use warnings for all kinds of pur-
poses, including providing debugging messages for your application.
The main difference between a warning and an exception is that a warning won’t stop the application.
When the interpreter encounters a warning, it outputs the warning information to the standard error
device unless the interpreter is ignoring the warning. In some cases, you need to tell the interpreter to
ignore a warning because the warning is due to a bug in someone else’s code, a known issue that you
can’t fix, or simply something that is obscuring other potential errors in your code. A standard warn-
ing looks like this:
__main__:1: UserWarning: deprecated
The elements are separated by colons (:) and each warning message contains the following elements
(unless you change the message formatting to meet a specific need).
➤➤
Function name (such as
__main__
)
Line number where the warning appears
➤
➤
Warning category
➤
➤
Message
➤
➤
You’ll discover more about these elements as the chapter progresses. In the meantime, it’s also
important to know that you can issue warnings, filter them, change the message formatting, and
perform other tasks using the warning-related functions shown in Table 12-1. You see these func-
tions in action in the sections that follow.
Do'stlaringiz bilan baham: |