C++ exceptions are broken in FreeBSD with gcc-compiled code?

Sergey Babkin babkin at verizon.net
Thu Apr 10 14:57:45 UTC 2008


Oh, this reminded me of something I've seen before. In some version of GCC
(3.96? 4.something?) if you declare a function with an explicit throw() 
declaration and then throw from it an exception that is not in the declaration,
the exception never gets caught. It just goes all the way out.

Any chance that this is one of these cases?

I don't remember the exact details but it looked
somewhat like this:

void f() throw exception;

voif f()
{
    throw(string("zzz"));
}

main()
{
  try {
    f();
  } catch(exception e) {
    ...
  } catch (string s) {
    ...
  }
}

-SB

>
>> > It works fine for me too, using FreeBSD 6-stable and the built-in gcc 
>> > 3.4.6
>> > as well as with gcc 4.2.4 20080305 installed from ports.
>> > No need to use -pthreads in either case
>> 
>> This means that this issue is STABLE-7.0 specific.
>
>I am not able to reproduce the problem here; I will compile the
>updated sources tonight to check if that changes anything:
>
># uname -sr
>FreeBSD 7.0-STABLE
>
># g++ --version
>g++ (GCC) 4.2.1 20070719  [FreeBSD]
>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.
>
># cat exc.C
>
>#include <iostream>
>#include <string>
>using namespace std;
>
>int main() {
>  try {
>    throw string("String");
>  } catch (string s) {
>    cout << "Caught an exception \"" << s << "\"\n";
>  }
>}
>
># g++ -o exc exc.C
># ./exc
>Caught an exception "String"
>_______________________________________________
>freebsd-hackers at freebsd.org mailing list
>http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
>To unsubscribe, send any mail to "freebsd-hackers-unsubscribe at freebsd.org"



More information about the freebsd-hackers mailing list