It looks like Serhiy answered your main question, but I wanted to mention that rather than simply printing the exception, you could also print the full traceback using the "traceback" module:
>>> import traceback >>> try: ... 1/0 ... except Exception as e: ... traceback.print_exc() ... Traceback (most recent call last): File "<stdin>", line 2, in <module> ZeroDivisionError: division by zero Whereas with simply using `print(e)` you only get: division by zero The former is far more useful and gives you all of the information from the last exception without raising it. I'd recommend looking further into the traceback module if you'd like more customization, but using traceback.print_exc() is a substantial improvement by itself. On Thu, Sep 26, 2019 at 8:40 AM <salemalbr...@gmail.com> wrote: > Hello, > > 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. > _______________________________________________ > 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/KHFQ4D2KQFZKHNUGV6SM27U3CI7EOXWJ/ > 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/DPRNDQGI45VSCU5M2LLJPPXTFT4INKVZ/ Code of Conduct: http://python.org/psf/codeofconduct/