help-gplusplus
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Cannot catch exceptions thrown in a shared library


From: Rüdiger Ranft
Subject: Cannot catch exceptions thrown in a shared library
Date: Tue, 06 Nov 2007 13:29:39 +0100
User-agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; de-AT; rv:1.8.1.6) Gecko/20070802 SeaMonkey/1.1.4

Hi all,

I got the problem that I can't catch an exception which is thrown in a
shared library under MS windows. Since we need to use exceptions to tell
the calling site if something went wrong, we need a working exception
mechanism.

The compilers I tried were g++-4.1.2 and g++-4.2.2, running unter cygwin
with mingw32 target. The compilers where generated from vanilla sources,
configure paramters are ../gcc-4.2.2/configure --host=i686-pc-cygwin
--build=i686-pc-cygwin --target=i586-pc-mingw32 --enable-languages=c,c++

So does anyone know how to enable the exception handling mechanism so it
works under windows?

bye
Rudi

-8<---8<---8<---8<---8<-- th.cpp
#include <stdexcept>

void x() throw(std::runtime_error)
{
        throw std::runtime_error("blubb");
}

-8<---8<---8<---8<---8<-- cat ct.cpp
#include <iostream>

extern void y();

int main()
{
        y();
}

-8<---8<---8<---8<---8<-- a.cpp
#include <iostream>
#include <stdexcept>

extern void x()throw(std::runtime_error);

void y()
{
        try
        {
                x();
        }
        catch(...)
        {
                std::cerr << "Exception\n";
        }
}
-8<---8<---8<---8<---8<--
$ /usr/local/bin/i586-pc-mingw32-g++ -shared th.cpp -o th.dll
$ /usr/local/bin/i586-pc-mingw32-g++ -shared -o a.dll a.cpp th.dll
$ /usr/local/bin/i586-pc-mingw32-g++ -o ct.exe ct.cpp a.dll
$ ./ct.exe

abnormal program termination
terminate called after throwing an instance of 'std::runtime_error'
  what():  blubb

$ /usr/local/bin/i586-pc-mingw32-g++ --version
i586-pc-mingw32-g++ (GCC) 4.2.2
Copyright (C) 2007 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]