diff options
Diffstat (limited to 'lib/csv.rb')
-rw-r--r-- | lib/csv.rb | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/lib/csv.rb b/lib/csv.rb index 595586a541..e1199185f9 100644 --- a/lib/csv.rb +++ b/lib/csv.rb @@ -1260,7 +1260,12 @@ class CSV file_opts = {encoding: Encoding.default_external}.merge(file_opts) retry end - csv = new(f, options) + begin + csv = new(f, options) + rescue Exception + f.close + raise + end # handle blocks like Ruby's open(), not like the CSV library if block_given? |