Wow, I have never realized that except’s expression is a full featured expression!
Best Regards Ilya Kulakov > On Sep 26, 2019, at 7:00 AM, Serhiy Storchaka <storch...@gmail.com> wrote: > > 26.09.19 12:07, salemalbr...@gmail.com пише: >> So when coding, at deferent stages we need different levels of error >> handling. For example at stage of finding the concept, initial >> implementation, alpha, releasing testing, etc. >> By some bits of code we can simulate enable/disable error handling. >> But it would be very helpful to have such thing built in the language with >> some more pythonic salt 😁. >> For example, >> Assume this behavior.. >> ************ >> SetExceptionLevel(50) >> try: >> x = 1 / 0 >> except(0) Exception as e: >> print(e) >> except (40) ZeroDivisionError as e1: >> x = math.inf >> except (40) ValueError as e2: >> x = None >> except(60) Exception as e3: >> raise e3 >> **************** >> i.e. one exception can have more than one handler and each handler has a >> level to enable it, >> so now for this example the first 2 exception will run only, >> If we want the last one to run also we need to change the first line to >> "SetExceptionLevel(70)" for example. >> The third one " ValueError " will never be triggered. >> And if no exception met the requirements "level and exception type" then the >> error will be raised out. > > It is not clear what your propose syntax means, but you can use e.g. such > code: > > except (ZeroDivisionError if level > 40 or ()) as e1: > x = math.inf > > If level > 0, you will catch ZeroDivisionError and set x = math.inf. > If level <= 40 the ZeroDivisionError exception will pass to other handlers. > _______________________________________________ > 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/K57OE77UM4ZSHP4E2L5FEKRRBNALCCGR/ > Code of Conduct: http://python.org/psf/codeofconduct/ _______________________________________________ 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/GQ6PEX5V6QFAO5ZTG3Q4RIRPYLUXK3B4/ Code of Conduct: http://python.org/psf/codeofconduct/