You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Original bug ID: 7163 Reporter: AltGr Status: closed (set by @mshinwell on 2016-12-08T09:56:28Z) Resolution: not a bug Priority: normal Severity: feature Version: 4.02.3 Target version: 4.03.1+dev Category: runtime system and C interface Monitored by:@diml@hcarty
Bug description
A common pattern for finalizing is:
let _ =
try ...
with e ->
finalize ();
raise e
The issue here is that finalize might use exceptions internally. OCaml generally handles this, but if finalize uses the same exception as e (e.g. Not_found), the backtrace gets mangled. There is indeed no way that I know of for OCaml to find which was the "right" instance of Not_found.
Since we now have Printexc.get_raw_backtrace available in the stdlib, a possible solution interface-wise would be to also provide a function raise_with_backtrace:
let _ =
try ...
with e ->
let bt = Printexc.get_raw_backtrace () in
finalize ();
raise_with_backtrace bt e
It feels weird to have to use Printexc for this (well, it already has get_callstack), but you get the idea. Ideally try..with would allow to match both exception and backtrace, but that's much too invasive.
Is anything like this already available ? Would it be suitable ?
If desired, I could have a look at it.
The text was updated successfully, but these errors were encountered:
In the end we didn't include the user-facing features in 4.03, but it's up to discussion for future releases.
PS: I found the name "finalizer" a bit confusing as I usually think of them for "GC finalizers" only, here it's "the stuff you put in finally blocks". Maybe "cleanup code" or "teardown code"?
Original bug ID: 7163
Reporter: AltGr
Status: closed (set by @mshinwell on 2016-12-08T09:56:28Z)
Resolution: not a bug
Priority: normal
Severity: feature
Version: 4.02.3
Target version: 4.03.1+dev
Category: runtime system and C interface
Monitored by: @diml @hcarty
Bug description
A common pattern for finalizing is:
let _ =
try ...
with e ->
finalize ();
raise e
The issue here is that finalize might use exceptions internally. OCaml generally handles this, but if finalize uses the same exception as e (e.g. Not_found), the backtrace gets mangled. There is indeed no way that I know of for OCaml to find which was the "right" instance of Not_found.
Since we now have Printexc.get_raw_backtrace available in the stdlib, a possible solution interface-wise would be to also provide a function raise_with_backtrace:
let _ =
try ...
with e ->
let bt = Printexc.get_raw_backtrace () in
finalize ();
raise_with_backtrace bt e
It feels weird to have to use Printexc for this (well, it already has get_callstack), but you get the idea. Ideally try..with would allow to match both exception and backtrace, but that's much too invasive.
Is anything like this already available ? Would it be suitable ?
If desired, I could have a look at it.
The text was updated successfully, but these errors were encountered: