[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Can't mix native exceptions and ObjC++
From: |
Lucas Schnorr |
Subject: |
Re: Can't mix native exceptions and ObjC++ |
Date: |
Mon, 22 Feb 2010 09:33:48 +0100 |
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
On Mon, Jan 12, 2009 at 14:38, Larry Campbell <lcampbel@akamai.com> wrote:
> On Jan 12, 2009, at 7:26 AM, David Chisnall wrote:
>
>> On 11 Jan 2009, at 22:06, Larry Campbell wrote:
>>
>>> On Jan 10, 2009, at 3:38 AM, Richard Frith-Macdonald wrote:
>>>
>>>> I use native objc exceptions with gcc-4.4.0. However, if you want the
>>>> uncaught exception handler to work, you need to have patched the runtime.
>>>
>>> Do you also use Obj-C++? That seems to be my problem. If it's all Obj-C,
>>> it seems OK, but if I have so much as one Obj-C++ module in my link, I get
>>> the "undefined reference to typeinfo for NSException *" link error.
>>
>> Are you trying to throw an exception in Objective-C and catch it in C++?
>> This error message is saying that a C++ catch block is unable to find the
>> type info needed for the C++ exception handling personality function to pick
>> the correct landing pad.
>>
>> David
>
> No. Remember, this is code that compiles & links & runs just fine when
> gnustep is built without native exception support. But as soon as I turn on
> --enable-native-objc-exceptions, my code no longer links.
>
> - lc
>
>
>
> _______________________________________________
> Discuss-gnustep mailing list
> Discuss-gnustep@gnu.org
> http://lists.gnu.org/mailman/listinfo/discuss-gnustep
>
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- Re: Can't mix native exceptions and ObjC++,
Lucas Schnorr <=