Implement a context manager called ExceptionSilencer, which can be used as follows:
with ExceptionSilencer(ValueError):
int("aa")
print("We can reach this point, because the exception was not propagated")We want our exception silencer to only silence the specific exception class that we are providing.
For example:
with ExceptionSilencer(Exception):
int("aa")
print("We cannot reach this point, because the exception was propagated")Alongside the solution, add tests to show that the solution is behaving as expected.
- Have 2 Python files -
exception_silencer.pyandexception_silencer_tests.py - Consider using the
isoperator.