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

Erik Trulsson ertr1013 at student.uu.se
Wed Apr 9 18:26:09 UTC 2008


On Wed, Apr 09, 2008 at 10:29:05AM -0700, Ted Faber wrote:
> On Wed, Apr 09, 2008 at 09:39:09AM -0700, Yuri wrote:
> > I am unable to make a C++ program to catch an exception using the the 
> > system g++ compiler.
> > 
> > > 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";
> >  }
> > }
> > 
> > 
> > * Failed attempts with system compiler (using /lib/libgcc_s.so.1 and 
> 
> FYI it works here:
> 
> zod:~$ cat > test.cc
> #include <iostream>
> #include <string>
> using namespace std;
> 
> int main() {
>  try {
>    throw string("String");
>  } catch (string s) {
>    cout << "Caught an exception \"" << s << "\"\n";
>  }
> }
> zod:~$ g++ test.cc 
> zod:~$ ./a.out
> Caught an exception "String"
> zod:~$ g++ -v 
> Using built-in specs.
> Target: i386-undermydesk-freebsd
> Configured with: FreeBSD/i386 system compiler
> Thread model: posix
> gcc version 4.2.1 20070719  [FreeBSD]
> zod:~$ uname -a
> FreeBSD zod.isi.edu 8.0-CURRENT FreeBSD 8.0-CURRENT #5: Tue Apr  1
> 13:00:38 PDT 2008     root at zod.isi.edu:/usr/obj/usr/src/sys/ZOD  i386
> 

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.





-- 
<Insert your favourite quote here.>
Erik Trulsson
ertr1013 at student.uu.se


More information about the freebsd-hackers mailing list