Sobes.tech
Junior — Senior

Context manager that suppresses exceptions and returns a specified value

livecode

Task condition

Create a context manager suppress that catches exceptions of a specified type, logs them, and instead of propagating the error, returns the value passed through the default parameter. Implement it as a regular class.

Example 1:

with suppress(ZeroDivisionError, default=0):
    1 / 0

Program output: 0

Context manager that suppresses exceptions and… - sobes.tech