43👍
This is very well-documented. But may be you just need Sentry?
try:
1/0
except Exception as e:
print('%s' % type(e))
>>>
integer division or modulo by zero (<type 'exceptions.ZeroDivisionError'>)
11👍
import traceback
try:
some_function()
except Exception as e:
message = traceback.format_exc()
print(message)
👤NVS
- Field Level Permission Django
- Paypal monthly subscription plan settings for first day of the month and making monthly recurring payment – django python
- How to set value of a ManyToMany field in Django?
- Gunicorn sync workers spawning processes
4👍
To print the exception using Python 3, you’ll want to use type(e)
. Example below:
try:
1/0
except Exception as e:
print(type(e))
>>> <class 'ZeroDivisionError'>
And then you can catch the exception with:
try:
1/0
except ZeroDivisionError:
print('Cannot divide by 0')
except Exception as e:
print(type(e))
>>> Cannot divide by 0
- Annotate django query if filtered row exists in second table
- Combining multiple Django templates in a single request
- Django – Change a ForeignKey relation to OneToOne
- Pycharm Django Debugging is really slow
- Tracking changes to Django Model instances
- Is it correct to modify old migration files in Django?
- Django migration relation does not exist
Source:stackexchange.com