JuliaLang / julia

The Julia Programming Language
https://julialang.org/
MIT License
45.76k stars 5.49k forks source link

Add option for `finalize` to not swallow error's for testing purposes. #13775

Open jakebolewski opened 9 years ago

jakebolewski commented 9 years ago

Currently when there is an error thrown in a finalizer, the error is swallowed and an error message is printed.

julia> type Foo
       end

julia> f = Foo()
Foo()

julia> finalizer(f, x -> error("foo"))

julia> finalize(f)
error in running finalizer: ErrorException("foo")

Could we add an option for the error not to get swallowed for testing purposes? When bugs are introduced into the finalizer function most CI tests will silently pass.

JeffBezanson commented 9 years ago

Would the exception get thrown from wherever GC happened to occur, or only the finalize function?

jakebolewski commented 9 years ago

The non-locality of throwing the error whenever GC happened seems a bit problematic, I was thinking of just adding an extra parameter to finalize(x, raise::Bool=false) which you could then just call explicitly in the test suite with finalize(x, true).

Perhaps throwing an error should be the default behavior when finalize is explicitly called by the user.

JeffBezanson commented 9 years ago

Agreed; it seems totally fine for this to just be part of finalize.