On Mon, Oct 12, 2020, at 17:16, jmwar...@gmail.com wrote:
> 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

It seems like this could be a good use case for pattern matching...

try:
    ...
    raise Exception(a, b, c, d, e, f)
except Exception as e match e.args:
    case (a: int, b: str, c, _, _ f):
       logger.warning(f"BAD THING {a} HAPPENED!")
       if not handle_it(a, b, c, f):
         raise

[Incidentally PEP 634 is very light on actual examples, and I'm having trouble 
visualizing what the syntax actually looks like, so please forgive me if I 
misunderstood what the pattern should look like]
_______________________________________________
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/I5SA3Q67DMKUVSOCLGG7K23XUQBQDMF5/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to