On Mon, Oct 12, 2020, at 17:16, jmward01@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]