Loading topic
try, except, and raise, and understand basic inheritance. It helps you decide when a built-in exception is enough and when a custom one is better.3 min readtry, except and raise, and know that a subclass inherits from its parent. You will define one custom exception, see what it inherits, and catch it.2 min readException and raise and catch it, as covered in the previous chapters. Here you will learn how to choose a name that reads well in a traceback and how to write a docstring that tells callers when to expect the exception.2 min readtry/except block and have already defined a class that subclasses Exception. Here you will raise that class and catch it correctly.2 min readtry, except, and raise, and call super().__init__. It shows how to organize several custom exceptions under one base class so callers can catch as much or as little as they need.2 min readsuper().__init__(). It also assumes you know try, except, and raise, and that you have a package base class like the AppError from the earlier chapters. The next chapter covers how args and __str__ behave. Here the goal is to attach da2 min read__init__ that calls super().__init__, and that you know how try, except, and raise work. Here you will see how an exception's args tuple relates to its message, and why that relationship matters.2 min readtry/except blocks and define a subclass of Exception. It shows how to keep the original error attached when you raise your own exception.2 min read__init__, as in the previous chapters. It also assumes you know that super().__init__() sets the exception's args.2 min readtry and except. It also assumes you know raise ... from. Everything here needs Python 3.11 or newer.2 min readraise ... from, and run basic tests with pytest. A test for an exception checks the type, the message, and the data the exception carries. It also checks that the original cause was kept.2 min read__init__, and chain with raise ... from. Here are the most common design mistakes and how to fix each one.3 min read