Qix- / better-exceptions

Pretty and useful exceptions in Python, automatically.
MIT License
4.6k stars 204 forks source link

Enable better exceptions in my app ? #56

Closed stuaxo closed 6 years ago

stuaxo commented 6 years ago

Hi, Is there an API I can call to enable better exceptions in my app. It's for Shoebot, where we basically exec python code to make graphics, we already have an home grown exception formatter thingy, but better exceptions looks better to me.

Cheers S

Delgan commented 6 years ago

Hi @stuaxo

I think you could use the better_exceptions.format_exception() function.

import sys, better_exceptions

try:
    a, b = 1, 0
    a / b
except ZeroDivisionError:
    exc, value, tb = sys.exc_info()

print(better_exceptions.format_exception(exc, value, tb))

Output:

Traceback (most recent call last):
  File "test.py", line 5, in <module>
    a / b
    │   └ 0
    └ 1
ZeroDivisionError: integer division or modulo by zero

Does it suit your needs?

stuaxo commented 6 years ago

Thanks, that's perfect.