I generally find exception objects are really just boilerplate heavy objects 
masking what I really want them to be, function calls:

class MySpecialException(Exception):
  def __init__(self, some, variables, i, am, tracking):
     self.some = some
     ...
...
try:
  if some_test_that_fails(variables):
    raise MySpecialException(a, b, c, d, e, f)
except MySpecialException as e:
  logger.warning(f"BAD THING {e.a} HAPPENED!")
  if not handle_it(e.a, e.b, e.c, e.f):
     raise
...


Instead of needing a whole new class definition, wouldn't it be nice to just 
have something like:

....
#notice there isn't a boilerplate custom class created!
try:
  if some_test_that_fails(variables):
    #I still have a base exception to fall back on for handlers that don't know 
my special exception
    raise Exception.my_special_exception(a, b, c, d, e, f)
except Exception.my_special_excpetion(a:int, b:str, d, e, f):
  logger.warning(f"BAD THING {a} HAPPENED!")
  if not handle_it(a, b, c, f):
    raise


The core idea here is that we are just passing control, so why make exceptions 
an exception to how control is normally passed, via functions.  Just a thought.
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/LHQEAPIKAMLBLKD5MHHVRTJ2UJVF436H/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to