How to reraise exception (raise the exception again) in Python

1 Answer

0 votes
try:
    f = open("file.txt")
except:
    print("except text:")
    raise


'''
run:

except text:
Traceback (most recent call last):
  File ".../test.py", line 2, in <module>
    f = open("file.txt")
FileNotFoundError: [Errno 2] No such file or directory: 'file.txt'

'''

 



answered Sep 11, 2018 by avibootz

Related questions

2 answers 277 views
2 answers 268 views
268 views asked Sep 11, 2018 by avibootz
2 answers 225 views
1 answer 306 views
3 answers 363 views
363 views asked Apr 27, 2021 by avibootz
...