-1

I have the code here:

import traceback

try:
    raise TypeError("Oups!")
except Exception as err:
    try:
        raise TypeError("Again !?!")
    except:
        pass
    traceback.print_tb(err.__traceback__)

I am not sure how I could put the error into a variable with the same format. The error looks like:

  File "C:/Users/user/PycharmProjects/project/file.py", line 4, in <module>
    raise TypeError("Oups!")

Can anyone help?

Top Of Tech
  • 305
  • 2
  • 11

1 Answers1

-1

The raise keyword throws the exception upwards, here quitting the programm as it reaches top level. You can save an exception like any other type as its just a class. Try this: smthing = TypeError("new error")

DownloadPizza
  • 3,307
  • 1
  • 12
  • 27