Skip to content

Instantly share code, notes, and snippets.

@frontdevops
Created October 24, 2022 21:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save frontdevops/06dc9b093f919a8a41f10630f088a4d5 to your computer and use it in GitHub Desktop.
Save frontdevops/06dc9b093f919a8a41f10630f088a4d5 to your computer and use it in GitHub Desktop.
import sys
import builtins
class Exception311(BaseException):
"""
This is a fallback for exception behavior like in python 3.11
"""
__notes__ = []
def __init__(self, *args):
super().__init__(*args)
def add_note(self, note):
self.__notes__.append(note)
def __str__(self):
return super().__str__() + '\n' + '\n'.join(self.__notes__)
if "3.11" != f"{sys.version_info.major}.{sys.version_info.minor}":
print("🧙‍️Run fallback python 3.10")
builtins.Exception = Exception311
try:
raise Exception("My message")
except Exception as e:
e.add_note("My note")
e.add_note("My note 2")
e.add_note("My note 3")
raise
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment