Download - All IT eBooks

Transcript
CHAPTER 10 ■ EXCEPTIONS
•
Raise: When you raise an exception, you both create an exception object and
cause Python’s core exception framework to begin passing it up from the current
method, through the method that called it, and the method calling that one, and
so on until the exception is dealt with using exception handling.
•
Traceback: A traceback is the human-readable report that an unhandled exception
creates when it is raised up to either the command prompt or the Python
interactive prompt.
•
try statements, try clauses, and except clauses: These compound statements are
the core of Python's exception handling. A try statement consists of a try clause
and (usually) one or more except clauses. Execution of the contents of the try
clause is attempted, and if an exceptional circumstance causes an exception
object to be created, Python looks for an except clause that matches the class of
the exception object or one of its superclasses.
Summary
You can now include sophisticated error handling techniques in your Python repertoire. You have seen
how the try...except...else...finally statement is used to handle exceptions and you now know how
to create exception classes of your own based on the existing exception class. The next chapter looks at
some of the most useful modules in Python’s standard library.
240