Good time of day! Please tell me how to display the error text and stacktrace in the console as it is done with an unhandled exception:

Traceback (most recent call last): File "file", line 67, in <module> M.logoutv() File "file", line 260, in __getattr__ raise AttributeError("Unknown IMAP4 command: '%s'" % attr) AttributeError: Unknown IMAP4 command: 'logoutv' 

I want to catch in try: process in except Exception as err:

    2 answers 2

    You can get the text of the stack stack using traceback :

     import traceback try: ... except Exception as e: print('Ошибка:\n', traceback.format_exc()) 

      Following your words, for example:

       try: do_something() except Exception as err: print(err) do_something_else() 
      • one
        As far as I remember, this will only display the type of exception, but not the traceback. - insolor
      • Screenshot - insolor
      • @insolor for sure, I just didn’t notice traceback - approximatenumber