Oct-22-2019, 09:05 AM
Hi,
I have a question about exception management
With the following code:
Usually in other language I do a cast, I tried it but I get "None" value.
Can I read filename from generic exception?
I have a question about exception management
With the following code:
try:
try:
with open('foo.json') as json_data_file:
pass
except FileNotFoundError as e:
print (f"f1: {e.filename}")
raise
except Exception as ex:
print (f"f2: {ex.filename}")
ex2 = FileNotFoundError(ex)
print (f"f3: {ex2.filename}")I get the following output:Output:f1: foo.json
f2: foo.json
f3: NoneWith "ex.filename" get a pylint warning about "Instance of 'Excepetion' has no 'filename' member".Usually in other language I do a cast, I tried it but I get "None" value.
Can I read filename from generic exception?
