Loading topic
except clause catches, what your program lets through, and what other developers expect when they read your code. This chapter wa6 min readtry, except and raise work, and how a subclass calls super().__init__. This chapter does not teach the mechanics of writing an exception class. The next chapters do that. Here you learn how to6 min readtry, except, and raise. You should also be comfortable with simple inheritance. By the end you will be able to write a custom exception class, choose its parent class, and predict how it beha5 min readException, and that you are comfortable with try, except, and raise. It covers how to name your exception classes, where to put them, and how to document them so other developers can use them without reading your source.5 min readException and that you know the basic try, except, and raise syntax. It covers how a custom exception behaves when you raise it and when you catch it. That includes how Python matches handlers, why their order matters, and how to 5 min readsuper().__init__, and handle errors with try, except, and raise. It also assumes you have already defined a single custom exception by subclassing Exception. Here you will organize several exceptions into one family so that 6 min readException and raise and catch it. It also assumes you know what super().__init__ does. The earlier chapters covered both. The examples reuse a base class named AppError, which is the single root of the package's exception hierarchy.6 min read__init__ that calls super().__init__, and use try/except/raise. It also assumes you have seen how an exception can carry attributes. Here you will learn what Python stores in args, how that value becomes the 4 min readtry/except blocks, define a subclass of Exception, and call super().__init__. It also assumes you have seen the AppError and ConfigError classes from earlier chapters. You will learn how Python links one exception to another, how raise ... from contro5 min read__init__ that calls super().__init__, and that you know Exception.args holds the constructor arguments. It covers a failure that shows up only when an exception crosses a process boundary: the exception can be pickled but cannot be unpickled.5 min readException, raise and catch it, and use raise ... from for chaining. It also assumes you run Python 3.11 or newer. Earlier chapters covered carrying data in attributes and controlling the message. Here you will add human-readab6 min readraise ... from, as covered earlier in this tutorial. You should also know the basics of pytest: test functions, assert, and running pytest from a terminal. Here you will learn what a good exception test checks, 5 min readException, add attributes with a custom __init__, and use raise ... from. Each section shows the mistake, explains why it hurts, and gives a fix.5 min read