redditwarp.util.except_without_context
#
- class redditwarp.util.except_without_context.except_without_context(*exceptions: type[BaseException])[source]#
Bases:
ContextManager
[bool
]A context manager for handling exceptions while ignoring the current exception context.
This is best explained through a series of examples:
Example 1:
#region common def f() -> None: try: raise LookupError except LookupError as e: raise KeyError from e #regionend try: raise PermissionError except PermissionError as e: f()
Result:
PermissionError During handling of the above exception, another exception occurred: LookupError The above exception was the direct cause of the following exception: KeyError
We don’t want PermissionError to show.
Example 2:
try: raise PermissionError except PermissionError as e: try: f() except Exception as e: raise e from None
Result:
KeyError
LookupError is missing.
Example 3:
with except_without_context(PermissionError) as ewc: raise PermissionError if ewc: f()
Result:
LookupError The above exception was the direct cause of the following exception: KeyError
Just right.
- exceptions: tuple[type[BaseException], ...]#
- yes: bool#