12.07.2015 Views

Is Python a

Is Python a

Is Python a

SHOW MORE
SHOW LESS
  • No tags were found...

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Chapter SummaryIn this chapter, we tackled coding user-defined exceptions. As we learned, exceptionsmay be implemented as string objects or class instance objects; however, classinstances are preferred today, and will be required in a future version of <strong>Python</strong>.Class exceptions are preferable because they support the concept of exception hierarchies(and are thus better for maintenance), allow data and behavior to be attachedto exceptions as instance attributes and methods, and allow exceptions to inheritdata and behavior from superclasses.We saw that in a try statement, catching a superclass catches that class, as well as allsubclasses below it in the class tree—superclasses become exception category names,and subclasses become more specific exception types within those categories. Wealso saw that the raise statement has been generalized to support a variety of formats,though most programs today simply generate and raise class instances.Although we explored both string and class-based alternatives in this chapter, exceptionobjects are easier to remember if you limit your scope to the class-based model<strong>Python</strong> encourages today—code each exception as a class, and inherit from Exceptionat the top of your exception trees, and you can forget the older string-based alternative.The next chapter wraps up this part of the book and the book at large by exploringsome common use cases for exceptions, and surveying commonly used tools for<strong>Python</strong> programmers. Before we get there, though, here’s this chapter’s quiz.Chapter Summary | 615

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!