Exceptions are also part of the principal functions that do one thing, and one thing only. The exception the function is handling (or raising) has to be consistent with the logic encapsulated on it.
In this example, we can see what we mean by mixing different levels of abstractions. Imagine an object that acts as a transport for some data in our application. It connects to an external component where the data is going to be sent upon decoding. In the following listing, we will focus on the deliver_event method:
class DataTransport: """An example of an object handling exceptions of different levels.""" retry_threshold: int = 5 retry_n_times: int = 3 def __init__(self, connector): self._connector ...