http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53944

             Bug #: 53944
           Summary: Can't catch C++ exception in Objective C
    Classification: Unclassified
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libobjc
        AssignedTo: unassig...@gcc.gnu.org
        ReportedBy: kostja.osi...@gmail.com


There is no way with GCC runtime to catch a C++ exception in Objective C code.
The catch-all clause doesn't work. 
At some point this limitation was documented, but later removed from the
manual.

Right now the code compiles, but fails to produce expected results.


kostja@atlas:~$ cat bar.cc 
extern "C" int bar()
{
    throw "exception";
}
kostja@atlas:~$ cat foo.m 
#include <stdio.h>
extern int bar();
int main()
{
    @try {
        bar();
    } @catch (...) {
        printf("caught\n");
    } @finally {
        printf("finally\n");
    }
}
kostja@atlas:~$ g++ -c -fexceptions bar.cc
kostja@atlas:~$ g++ -c -fexceptions -fobjc-exceptions  foo.m
kostja@atlas:~$ g++ foo.o bar.o -lobjc                      
kostja@atlas:~$ ./a.out 
terminate called after throwing an instance of 'char const*'
[1]    20822 abort (core dumped)  ./a.out

Reply via email to