diff --git a/src/NCDatasets.jl b/src/NCDatasets.jl index 81b7978f..d14ccecb 100644 --- a/src/NCDatasets.jl +++ b/src/NCDatasets.jl @@ -388,7 +388,12 @@ end function Dataset(f::Function,args...; kwargs...) ds = Dataset(args...; kwargs...) - f(ds) + try + f(ds) + catch + close(ds) + rethrow() + end close(ds) end