Abstract
When writing computer programs, it is usually possible to discern between a normal course of events and something that’s exceptional (out of the ordinary). Such exceptional events might be errors (such as trying to divide a number by zero) or simply something you might not expect to happen very often. To handle such exceptional events, you might use conditionals everywhere the events might occur (for example, have your program check whether the denominator is zero for every division). However, this would not only be inefficient and inflexible, but would also make the programs illegible. You might be tempted to ignore these exceptional events and just hope they won’t occur, but Python offers a powerful alternative through its exception objects.
This is a preview of subscription content, log in via an institution.
Buying options
Tax calculation will be finalised at checkout
Purchases are for personal use only
Learn about institutional subscriptionsPreview
Unable to display preview. Download preview PDF.
Rights and permissions
Copyright information
© 2008 Magnus Lie Hetland
About this chapter
Cite this chapter
Hetland, M.L. (2008). Exceptions. In: Beginning Python. Apress. https://doi.org/10.1007/978-1-4302-0634-7_8
Download citation
DOI: https://doi.org/10.1007/978-1-4302-0634-7_8
Publisher Name: Apress
Print ISBN: 978-1-59059-982-2
Online ISBN: 978-1-4302-0634-7
eBook Packages: Professional and Applied ComputingApress Access BooksProfessional and Applied Computing (R0)