-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Closed
Description
The following example shows an undesired behaviour of finally as a statement:
proc do_stuff(out_filename: string): bool =
var out_file: TFile
try:
if not out_file.open(out_filename, fmWrite):
echo "Could not open ", out_filename, " for writing."
return
except EOutOfMemory:
return
finally: out_file.close
try: out_file.write("yeah\n")
except EIO:
echo "Could not write header"
return
result = true
when isMainModule:
echo "Did stuff? ", do_stuff("test.txt")When run the output is
Could not write header
Did stuff? false
The file test.txt is created but empty. If the finally line is commented out, the example works and the test file gets written to. This suggest that finally forces the next try/except block to fail.
Metadata
Metadata
Assignees
Labels
No labels