X
X
xSkyFoXx2012-09-06 09:00:29
Python
xSkyFoXx, 2012-09-06 09:00:29

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

3 answer(s)
D
dikkini, 2012-09-06
@dikkini

do logging

A
Alexey Akulovich, 2012-09-06
@AterCattus

Maybe sys.excepthook will do ?

M
marazmiki, 2012-09-06
@marazmiki

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
>>> 

But it's better to uselogging

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question