Exceptions not transporting across dll boundaries in certain cases

View: New views
6 Messages — Rating Filter:   Alert me  

Exceptions not transporting across dll boundaries in certain cases

by Chris Spencer-8 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi all,

I have stumbled across a problem with exceptions not being transported
across dll boundaries in quite specific circumstances. Say you have a
class in a dll file with function doSomething() and virtual function
catchSomething(). If doSomething() catches an exception it calls
catchSomething(). If catchSomething() subsequently re-throws the
excption using throw;, it carries through and doSomething() throws as
expected. If however you override catchSomething in your own class
(outside the dll) and do the same (throw;), the application exits with
'terminate called without an active exception'. See the attached code
for an example.

This looks like a mingw bug to me, it works fine on Linux.

Any suggestions on fixes/workarounds (other than static linking (which
does work, but I'd rather use dynamic linking))?

$ mingw32-g++ --version
mingw32-g++ (Gentoo 4.4.2 p1.0) 4.4.2

Tested on Windows 7 and Wine.

Chris.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.11 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAkrsDkcACgkQ6iqRtkAADZjVvgCePigBCpjDVefuhXfgJfGu+mAR
/74An1Cos3avIV72fuYpBUq8quqEjw9m
=SjyJ
-----END PGP SIGNATURE-----

#include <iostream>
#include <stdexcept>

#include "except.hpp"

using namespace std;

void MyClass::doSomething() {
        try {
                throw runtime_error("something");
        } catch (...) {
                catchSomething();
        }
}

void MyClass::catchSomething() {
        cerr << "MyClass::catchSomething()" << endl;
        throw;
}

class MyClass {
        public:
                void doSomething();
                virtual void catchSomething();
};

#include <iostream>
#include <stdexcept>

#include "except.hpp"

using namespace std;

class MyDerivedClass: public MyClass {
        public:
                void catchSomething() {
                        cerr << "MyDerivedClass::catchSomething()" << endl;
                        throw;
                }
};

int main() {
        try {
                MyDerivedClass obj;
                obj.doSomething();
        } catch (exception& e) {
                cerr << e.what() << endl;
        }
        return 0;
}

all:
        mingw32-g++ -Wall -Wextra -pedantic -O3 -shared except.cpp -o libexcept.dll
        mingw32-g++ -Wall -Wextra -pedantic -O3 -L. main.cpp -lexcept -o except.exe

------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
_______________________________________________
MinGW-users mailing list
MinGW-users@...

This list observes the Etiquette found at
http://www.mingw.org/Mailing_Lists.
We ask that you be polite and do the same.

Most annoying abuses are:
1) Top posting
2) Thread hijacking
3) HTML/MIME encoded mail
4) Improper quoting
5) Improper trimming
_______________________________________________
You may change your MinGW Account Options or unsubscribe at:
https://lists.sourceforge.net/lists/listinfo/mingw-users

Re: Exceptions not transporting across dll boundaries in certain cases

by Greg Chicares-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On 2009-10-31 10:15Z, Chris Spencer wrote:

>
> I have stumbled across a problem with exceptions not being transported
> across dll boundaries in quite specific circumstances. Say you have a
> class in a dll file with function doSomething() and virtual function
> catchSomething(). If doSomething() catches an exception it calls
> catchSomething(). If catchSomething() subsequently re-throws the
> excption using throw;, it carries through and doSomething() throws as
> expected. If however you override catchSomething in your own class
> (outside the dll) and do the same (throw;), the application exits with
> 'terminate called without an active exception'. See the attached code
> for an example.
>
> This looks like a mingw bug to me, it works fine on Linux.
>
> Any suggestions on fixes/workarounds (other than static linking (which
> does work, but I'd rather use dynamic linking))?

Another workaround would be to use MinGW gcc-3.4.5: it prints
  MyDerivedClass::catchSomething()
  something
which I believe is what you intend.

------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
_______________________________________________
MinGW-users mailing list
MinGW-users@...

This list observes the Etiquette found at
http://www.mingw.org/Mailing_Lists.
We ask that you be polite and do the same.

Most annoying abuses are:
1) Top posting
2) Thread hijacking
3) HTML/MIME encoded mail
4) Improper quoting
5) Improper trimming
_______________________________________________
You may change your MinGW Account Options or unsubscribe at:
https://lists.sourceforge.net/lists/listinfo/mingw-users

Re: Exceptions not transporting across dll boundaries in certain cases

by Chris Spencer-8 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Greg Chicares wrote:
> Another workaround would be to use MinGW gcc-3.4.5: it prints
>   MyDerivedClass::catchSomething()
>   something
> which I believe is what you intend.

Yes, that is what I wanted. I would rather have it compatible with GCC 4
though.

Thanks, Chris.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.11 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAkrsTpsACgkQ6iqRtkAADZiCVQCdFNWzC6HqiAdVKz/nr0+gI+SI
GS4AniBtEQskD1fo6730vBBhzhlxkpK7
=0G5R
-----END PGP SIGNATURE-----

------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
_______________________________________________
MinGW-users mailing list
MinGW-users@...

This list observes the Etiquette found at
http://www.mingw.org/Mailing_Lists.
We ask that you be polite and do the same.

Most annoying abuses are:
1) Top posting
2) Thread hijacking
3) HTML/MIME encoded mail
4) Improper quoting
5) Improper trimming
_______________________________________________
You may change your MinGW Account Options or unsubscribe at:
https://lists.sourceforge.net/lists/listinfo/mingw-users

Re: Exceptions not transporting across dll boundaries in certain cases

by Takashi Ono :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi Chris,

In message "[Mingw-users] Exceptions not transporting across dll boundaries in
        certain cases",
Chris Spencer wrote...
 >expected. If however you override catchSomething in your own class
 >(outside the dll) and do the same (throw;), the application exits with
 >'terminate called without an active exception'. See the attached code

As I have reported on this mailing list before, It will work if and only if you use
dynamic linking for libstdc++ for all modules built with mingw gcc 4.x.x.

It is a headache for me as such a code is essential in OpenOffice.org to bridge exception
handlings between C++ and other frameworks. When I choose dynamic linking of libstdc++, I
have to be ready to supply libstdc++ source code.

Best Regards,

----
 Takashi Ono(HK Freak)
 mailto:t_ono@... or MHF00056@...
        (Personal Address, checked every morning/evening and holidays)
 mailto:t_ono@...
        (Address for business, checked every working days)
 http://www.hkfreak.net

------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
_______________________________________________
MinGW-users mailing list
MinGW-users@...

This list observes the Etiquette found at
http://www.mingw.org/Mailing_Lists.
We ask that you be polite and do the same.

Most annoying abuses are:
1) Top posting
2) Thread hijacking
3) HTML/MIME encoded mail
4) Improper quoting
5) Improper trimming
_______________________________________________
You may change your MinGW Account Options or unsubscribe at:
https://lists.sourceforge.net/lists/listinfo/mingw-users

Re: Exceptions not transporting across dll boundaries in certain cases

by Chris Spencer-8 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Takashi Ono wrote:
> As I have reported on this mailing list before, It will work if and only if you use
> dynamic linking for libstdc++ for all modules built with mingw gcc 4.x.x.
>
> It is a headache for me as such a code is essential in OpenOffice.org to bridge exception
> handlings between C++ and other frameworks. When I choose dynamic linking of libstdc++, I
> have to be ready to supply libstdc++ source code.

Ok. Looking on my system I can only see a static version
(/usr/lib64/gcc/mingw32/4.4.2/libstdc++.a), I take it I am going to have
to compile the shared version myself then?

Chris.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.11 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAkrtaUUACgkQ6iqRtkAADZiI/ACcClobPp3bSkzAkAk/u1xkwiBf
KlsAn1+D0JrIT0Yq2lw12Gctd/D9gcn+
=pkQ8
-----END PGP SIGNATURE-----

------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
_______________________________________________
MinGW-users mailing list
MinGW-users@...

This list observes the Etiquette found at
http://www.mingw.org/Mailing_Lists.
We ask that you be polite and do the same.

Most annoying abuses are:
1) Top posting
2) Thread hijacking
3) HTML/MIME encoded mail
4) Improper quoting
5) Improper trimming
_______________________________________________
You may change your MinGW Account Options or unsubscribe at:
https://lists.sourceforge.net/lists/listinfo/mingw-users

Re: Exceptions not transporting across dll boundaries in certain cases

by Kai Tietz-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

2009/11/1 Chris Spencer <spencercw@...>:

> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> Takashi Ono wrote:
>> As I have reported on this mailing list before, It will work if and only if you use
>> dynamic linking for libstdc++ for all modules built with mingw gcc 4.x.x.
>>
>> It is a headache for me as such a code is essential in OpenOffice.org to bridge exception
>> handlings between C++ and other frameworks. When I choose dynamic linking of libstdc++, I
>> have to be ready to supply libstdc++ source code.
>
> Ok. Looking on my system I can only see a static version
> (/usr/lib64/gcc/mingw32/4.4.2/libstdc++.a), I take it I am going to have
> to compile the shared version myself then?

Yes, enter your /usr/lib64gcc/mingw32/4.4.2/ folder and do the following steps.

dlltool --output-def libstdc++.def --export-all libstdc++.a
gcc -shared -o libstdc++.dll -Wl,--out-implib,libstdc++.dll.a
libstdc++.def libstdc++.a

Then move the generated libstdc++.dll to you sysroot bin folder.

But be aware that this shared version has issues in some cases. But
the exception throwing over DLL boundaries should by solved by this.

Cheers,
Kai



--
|  (\_/) This is Bunny. Copy and paste
| (='.'=) Bunny into your signature to help
| (")_(") him gain world domination

------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
_______________________________________________
MinGW-users mailing list
MinGW-users@...

This list observes the Etiquette found at
http://www.mingw.org/Mailing_Lists.
We ask that you be polite and do the same.

Most annoying abuses are:
1) Top posting
2) Thread hijacking
3) HTML/MIME encoded mail
4) Improper quoting
5) Improper trimming
_______________________________________________
You may change your MinGW Account Options or unsubscribe at:
https://lists.sourceforge.net/lists/listinfo/mingw-users