This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug libobjc/53944] New: Can't catch C++ exception in Objective C


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: unassigned@gcc.gnu.org
        ReportedBy: kostja.osipov@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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]