Python Forum
Pythonn 3 getting the __traceback__attribute of an exception
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Pythonn 3 getting the __traceback__attribute of an exception
#1
Python3 documentation states:
A traceback object is normally created automatically when an exception is raised and attached to it as the __traceback__ attribute, which is writable.

What is the trick to get this traceback or what is wrong into my code.
import traceback


class MyException(Exception):

        def __init__(self, mymessage):
                super().__init__

                # do special things
                (print, mymessage)


def essai():

    raise MyException(' myp message')


if __name__ == '__main__':

    essai()
Reply
#2
Use
if __name__ == '__main__':
    try:
        essai()
    except Exception as exc:
        t = exc.__traceback__
        print(t)
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  During handling of the above exception, another exception occurred Skaperen 7 26,889 Dec-21-2018, 10:58 AM
Last Post: Gribouillis

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020