I am trying to create generic exception handler - for where I can set an arg to return in case of exception.
instead of doing:
try:
...
except Exception:
return list()
try:
...
except Exception:
return dict()
try:
...
except Exception:
return str()
I would like to create system whereby I have a generic exception handler that returns an arg I provide. e.g,
def handler(code, default):
try:
code
except Exception:
return default
def mains():
code = <code to execute>
default = str()
return handler(code, dafault)
but in a more pythonic way
try..exceptdirectly to make the error handling obvious.