Hi This is a bug in GCC.
obj-c++.dg/try-catch-[29].mm (objc exceptions are broken) fails with the GNU Runtime http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23616 Quick and dirty fix here: #import <Foundation/NSException.h> #if defined(__cplusplus) && defined(__GNUC__) \ && defined(GNUSTEP) && defined(_NATIVE_OBJC_EXCEPTIONS) // gcc 5.4.3 #if __GNUC__ < 5 || \ (__GNUC__ == 5 && \ (__GNUC_MINOR__ < 4 || \ (__GNUC_MINOR__ == 4 && \ __GNUC_PATCHLEVEL__ < 3))) #undef NS_DURING #undef NS_HANDLER #undef NS_ENDHANDLER #define NS_DURING @try { #define NS_HANDLER } @catch (id) { \ NSException* localException = \ [NSException exceptionWithName:@"Unknown" \ reason:@"Unknown" \ userInfo:nil]; \ { #define NS_ENDHANDLER } \ } #endif #endif #import <Foundation/Foundation.h> int main() { NSAutoreleasePool* pool = nil; NS_DURING { pool = [[NSAutoreleasePool alloc] init]; [NSException raise:@"foo" format:@"bar"]; } NS_HANDLER { NSLog(@"%s", [[localException description] UTF8String]); } NS_ENDHANDLER; [pool release]; return 0; } Isamu Lucas Schnorr wrote: > > Hi, > > I think I got the same kind of error when dealing with NSException and > using g++ to compile. > > I have a GNUmakefile: > > include $(GNUSTEP_MAKEFILES)/common.make > TOOL_NAME = ExceptionTest > ExceptionTest_OBJC_FILES = source.m > include $(GNUSTEP_MAKEFILES)/tool.make > > And the source.m like this > #include<Foundation/Foundation.h> > > int main(int argc, char **argv) > { > NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; > > @try { > @throw [NSException exceptionWithName:@"Throwing a test exception" > reason:@"Testing the @throw directive." > userInfo:nil]; > } > @catch (id theException) { > NSLog(@"%p", theException); > NSLog(@"%@", theException); > } > @finally { > NSLog(@"This always happens."); > } > > NSLog(@"Leaving ..."); > [pool release]; > return 0; > } > > Everything works fine during execution: > 2010-02-22 09:28:40.536 ExceptionTest[6763] 0x14ffed0 > 2010-02-22 09:28:40.538 ExceptionTest[6763] <NSException: 0x14ffed0> > NAME:Throwing a test exception REASON:Testing the @throw directive. > 2010-02-22 09:28:40.538 ExceptionTest[6763] This always happens. > 2010-02-22 09:28:40.538 ExceptionTest[6763] Leaving ... > > But, if a rename the file source.m to source.mm and > change this line of GNUmakefile from > ExceptionTest_OBJC_FILES = source.m > to > ExceptionTest_OBJCC_FILES = source.mm > > I get this during execution: > 2010-02-22 09:29:46.653 ExceptionTest[6818] 0x1d3fc60 > Segmentation fault > > GDB helps more or less, it says that the problem is with the NSLog > when trying to access the theException variable. > > 2010-02-22 09:30:09.355 ExceptionTest[6822] 0x67ecb0 > > Program received signal SIGSEGV, Segmentation fault. > 0x00007ffff728da55 in objc_msg_lookup () from /usr/lib/libobjc.so.2 > (gdb) bt > #0 0x00007ffff728da55 in objc_msg_lookup () from /usr/lib/libobjc.so.2 > #1 0x00007ffff77eda92 in ?? () from /usr/lib/libgnustep-base.so.1.19 > #2 0x00007ffff7819a09 in ?? () from /usr/lib/libgnustep-base.so.1.19 > #3 0x00007ffff7942154 in ?? () from /usr/lib/libgnustep-base.so.1.19 > #4 0x00007ffff79a8722 in ?? () from /usr/lib/libgnustep-base.so.1.19 > #5 0x00007ffff78d525e in NSLogv () from /usr/lib/libgnustep-base.so.1.19 > #6 0x00007ffff78d4e8d in NSLog () from /usr/lib/libgnustep-base.so.1.19 > #7 0x0000000000400c2b in main (argc=1, argv=0x7fffffffdf78) at > source.mm:14 > > Does anyone know how to handle objective-c exceptions when compiling > with g++ or a work-around? > I think in this case I am dealing only with obj-c exceptions (no > mixing with c++ exceptions), > so I think it should work. > > Lucas > > -- View this message in context: http://old.nabble.com/Can%27t-mix-native-exceptions-and-ObjC%2B%2B-tp14508121p27886720.html Sent from the GNUstep - General mailing list archive at Nabble.com. _______________________________________________ Discuss-gnustep mailing list [email protected] http://lists.gnu.org/mailman/listinfo/discuss-gnustep
