Answer the question
In order to leave comments, you need to log in
Is it possible to catch all exceptions thrown in my program without using try-except?
During the execution of my python program, I sometimes have exceptions that, in general, do not break the main logic, but which I would not be superfluous to know about. That's just how to catch all the exceptions that arise in the interpreter, so that later they can either be stored or sent somewhere to yourself?
Answer the question
In order to leave comments, you need to log in
In the forehead, the easiest way to do this is:
>>> def a():
... raise TypeError("oops")
...
>>> try:
... a()
... except Exception as e:
... print("{type} raised: {message}".format(type=type(e), message=e))
... raise
...
<type 'exceptions.TypeError'> raised: oops
Traceback (most recent call last):
File "<stdin>", line 2, in <module>
File "<stdin>", line 2, in a
TypeError: oops
>>>
logging
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question