Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class ExceptionInterceptor:
- def __init__(self, *exceptions):
- self.exceptions = exceptions
- def __enter__(self):
- pass
- def __exit__(self, exc_type, exc_value, traceback):
- if exc_type in self.exceptions:
- return True
- else:
- return False
- with ExceptionInterceptor(ValueError):
- value = input("Enter a number: ")
- try:
- value = int(value)
- except ValueError:
- print("Invalid input!")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement