Thread overview
[Issue 19831] throw/catch in scope(exit) crashes with illegal instruction
May 02, 2019
FeepingCreature
May 02, 2019
FeepingCreature
May 03, 2019
FeepingCreature
May 03, 2019
FeepingCreature
May 10, 2019
Dlang Bot
May 16, 2019
Dlang Bot
May 02, 2019
https://issues.dlang.org/show_bug.cgi?id=19831

--- Comment #1 from FeepingCreature <default_357-line@yahoo.de> ---
As far as I can see, what happens is it tries to format the exception inside
foo(), goes into core.demangle.doDemangle, throws a ParseException, forgets how
to cope with `catch (ParseException)` and falls right through to `catch
(Exception)`, where it assert(false)s out.

Why? Who knows. Dark dwarf magic.

--
May 02, 2019
https://issues.dlang.org/show_bug.cgi?id=19831

--- Comment #2 from FeepingCreature <default_357-line@yahoo.de> ---
https://run.dlang.io/is/49cEHl Cleaner repo of the underlying issue.

--
May 03, 2019
https://issues.dlang.org/show_bug.cgi?id=19831

--- Comment #3 from FeepingCreature <default_357-line@yahoo.de> ---
It's exception chaining. It uses the type of the originally thrown exception, even though the exception it's currently looking at has a different type.

--
May 03, 2019
https://issues.dlang.org/show_bug.cgi?id=19831

FeepingCreature <default_357-line@yahoo.de> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |EH, safe, wrong-code
           Severity|regression                  |major

--- Comment #4 from FeepingCreature <default_357-line@yahoo.de> ---
Note that this leads to potential memory corruption in @safe: https://run.dlang.io/is/rP2yXU

And what happens here in detail is that it inspects "current exceptions in flight" to select the type of handler to jump to, see druntime dwarfeh.d getClassInfo, but it doesn't at all account for the fact that an exception may be thrown and caught solely inside the finally handler, never being chained at all.

To fix this, exception chaining must only happen after the second exception being thrown passes the finally block originally triggered by the exception it'll be chained to.

--
May 10, 2019
https://issues.dlang.org/show_bug.cgi?id=19831

Dlang Bot <dlang-bot@dlang.rocks> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |pull

--- Comment #5 from Dlang Bot <dlang-bot@dlang.rocks> ---
@FeepingCreature created dlang/druntime pull request #2602 "Try to fix issue 19831 without understanding by copying the behavior from __dmd_personality_v0" fixing this issue:

- Try to fix issue 19831 without understanding by copying the behavior from __dmd_personality_v0

https://github.com/dlang/druntime/pull/2602

--
May 16, 2019
https://issues.dlang.org/show_bug.cgi?id=19831

Dlang Bot <dlang-bot@dlang.rocks> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|---                         |FIXED

--- Comment #6 from Dlang Bot <dlang-bot@dlang.rocks> ---
dlang/druntime pull request #2602 "Try to fix issue 19831 without understanding by copying the behavior from __dmd_personality_v0" was merged into stable:

- 7a3d881525ad856e78a49afa39de5e05ba9f4eda by FeepingCreature:
  fix issue 19831: select the appropriate exception handler analogously to
__dmd_personality_v0 (ignoring in-flight exceptions that we haven't collided
with yet)

https://github.com/dlang/druntime/pull/2602

--