Qix-/better-exceptions

Enable better exceptions in my app ?

Closed this issue · 2 comments

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

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
    │   └ 01
ZeroDivisionError: integer division or modulo by zero

Does it suit your needs?

Thanks, that's perfect.