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 276 views
2 answers 266 views
266 views asked Sep 11, 2018 by avibootz
2 answers 224 views
1 answer 304 views
3 answers 361 views
361 views asked Apr 27, 2021 by avibootz
...