[uClibc]gcc 2.95.3 exception handling does not work

Van Rafelghem, Dominique VanRafelghemD at intheairnet.com
Thu May 22 21:35:59 UTC 2003


Hi,

Processor : 5272 ColdFire
uClinux dist. : uClinux-20030305.tar.gz
Tool Chain : m68k-elf-tools-20030314.sh.
uClibc mod : enabled Posix threading support


Exception handling with gcc 2.95.3  has a problem.  When my code throws an
exception it correctly executes the exception class code (calls the copy
constructor as can be seen by the output on the console).  But then proceeds
to call the terminate function and kills the application.  This behavior
would be acceptable if there wasn't a catch clause in the code but there is.
In fact there are 2 catch clauses, the last one being a catch all, and still
the program terminates abnormally.

Below is the code that throws the exception and catches the exception.  This
code works fine on my Red Hat Linux machine using the 2.96 gcc compiler.
This code is a modified version of Steve Rowe's code who wrote an e-mail
about this problem to the uClinux mailing list back in December of 2001
(thanks Steve).

// ------------ start of code ------------------------------------------
#include <iostream>

using namespace std;

class MyException
{
   public:
      MyException() {}
      MyException(const MyException& copy) { cout << "copy called" << endl;
}
};

void test(void)
{
   throw MyException();
}

int main()
{
   cout << "program starting" << endl;

   try
   {
      test();
      cout << "Test succeeded." << endl;
   }
   catch (MyException mx)
   {
      cout << "Caught MyException exception: " << endl;
   }
   catch (...)
   {
      cout << "Unhandled exception." << endl;
   }

   return 0;
}

// --------------------- end of code ------------------------------

The following is used to compile and link the program.  The file is called
exception.cpp and produces the exception binary.

m68k-elf-g++ -m5307 -D_GNU_SOURCE -D__unix    -c -o exception.o
exception.cpp
m68k-elf-g++ -m5307 -D_GNU_SOURCE -D__unix -Wl,-elf2flt -o exception
exception.o -lc -lgcc

This problem is a show stopper for me, as much of the code I am trying to
port uses exceptions.  Any help with this matter will be greatly
appreciated.  Thanks.

Dominique

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.busybox.net/pipermail/uclibc/attachments/20030522/1953a868/attachment-0001.htm 


More information about the uClibc mailing list