diff options
Diffstat (limited to 'dns/exception.py')
-rw-r--r-- | dns/exception.py | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/dns/exception.py b/dns/exception.py index 8f1d488..9486f45 100644 --- a/dns/exception.py +++ b/dns/exception.py @@ -126,3 +126,17 @@ class Timeout(DNSException): """The DNS operation timed out.""" supp_kwargs = {'timeout'} fmt = "The DNS operation timed out after {timeout} seconds" + + +class ExceptionWrapper: + def __init__(self, exception_class): + self.exception_class = exception_class + + def __enter__(self): + return self + + def __exit__(self, exc_type, exc_val, exc_tb): + if exc_type is not None and not isinstance(exc_val, + self.exception_class): + raise self.exception_class() from exc_val + return False |