1

Usually it is advised to initialize cgitb at the beginning of a script with the function cgitb.enable().

But how can I do to use cgitb to format a special exception I catched in a try/except block, without registering cgitb as a global exception handler?

I suppose it would look like this:

import cgitb
try:
    1/0
except Exception as exc:
    print(cgitb.something(exc))
azmeuk
  • 4,026
  • 3
  • 37
  • 64

1 Answers1

1
import cgitb
import sys
try:
    1/0
except Exception:
    print(cgitb.text(sys.exc_info()))
azmeuk
  • 4,026
  • 3
  • 37
  • 64