January 01, 2011 [dmd-internals] Relation between D and C++ exception handling on Windows | ||||
---|---|---|---|---|
| ||||
Consider this simple program: ---- void main() { try { throw new Exception("xxx"); } catch (Exception e) {} } --- The map file includes these functions: test0.map: 0002:0000D838 ?__internal_cpp_framehandler@@YA?AW4_EXCEPTION_DI SPOSITION@@PAUfunc_data@@PAU_EXCEPTION_RECORD@@PAU_CPP_Establisher_Frame@@PAU_CO NTEXT@@PAX at Z 0040F838 test0.map: 0002:0000D814 __cpp_framehandler 0040F814 test0.map: 0002:0000D814 __cpp_framehandler 0040F814 test0.map: 0002:0000D838 ?__internal_cpp_framehandler@@YA?AW4_EXCEPTION_DI SPOSITION@@PAUfunc_data@@PAU_EXCEPTION_RECORD@@PAU_CPP_Establisher_Frame@@PAU_CO NTEXT@@PAX at Z 0040F838 I don't like this at all. Why is the C++ exception handler being linked into a D program? This is important, because the C++ exception behaviour is different to D. I've just spent the best part of a week trying to track down bug 1513 ("try/catch/finally misbehavior on windows"), which has turned out to be the most difficult bug I've ever seen. I'm finding it extremely difficult since the Microsoft documentation is practically non-existent, and DMC seems to have a unique implementation. Now I'm starting to suspect that part of the C++ exception handling mechanism may be involved, which would be bad. Quick question to Walter -- is it possible that the D exception handlers are sometimes called from the C++ handler? |
January 01, 2011 [dmd-internals] Relation between D and C++ exception handling on Windows | ||||
---|---|---|---|---|
| ||||
Posted in reply to Don Clugston |
Don Clugston wrote:
> Consider this simple program:
> ----
> void main()
> {
> try {
> throw new Exception("xxx");
> }
> catch (Exception e) {}
> }
> ---
> The map file includes these functions:
>
> test0.map: 0002:0000D838 ?__internal_cpp_framehandler@@YA?AW4_EXCEPTION_DI
> SPOSITION@@PAUfunc_data@@PAU_EXCEPTION_RECORD@@PAU_CPP_Establisher_Frame@@PAU_CO
> NTEXT@@PAX at Z 0040F838
> test0.map: 0002:0000D814 __cpp_framehandler 0040F814
> test0.map: 0002:0000D814 __cpp_framehandler 0040F814
> test0.map: 0002:0000D838 ?__internal_cpp_framehandler@@YA?AW4_EXCEPTION_DI
> SPOSITION@@PAUfunc_data@@PAU_EXCEPTION_RECORD@@PAU_CPP_Establisher_Frame@@PAU_CO
> NTEXT@@PAX at Z 0040F838
>
> I don't like this at all. Why is the C++ exception handler being
> linked into a D program?
> This is important, because the C++ exception behaviour is different to D.
> I've just spent the best part of a week trying to track down bug 1513
> ("try/catch/finally misbehavior on windows"), which has turned out to
> be the most difficult bug I've ever seen.
> I'm finding it extremely difficult since the Microsoft documentation
> is practically non-existent, and DMC seems to have a unique
> implementation. Now I'm starting to suspect that part of the C++
> exception handling mechanism may be involved, which would be bad.
>
> Quick question to Walter -- is it possible that the D exception handlers are sometimes called from the C++ handler?
>
>
Yes. The D exception handling code for windows uses the DMC++ exception handling, which is itself layered on top of the Windows Structured Exception Handling mechanism. To say it's complicated is an understatement. DMC++'s implementation used to be ABI compatible with MSC's, though MSC has a habit of changing it all the time, so that is likely no longer true.
D for Linux has its own unique exception handling mechanism, because:
1. I couldn't figure out the g++ mechanism (didn't try that hard, but
there is no documentation for it)
2. Being able to throw a C++ exception and catch it in D turned out to
not be something people wanted to do
|
Copyright © 1999-2021 by the D Language Foundation