discuss-gnustep
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Mysterious crash in NSRunLoop, using libobjc2 on Linux


From: Lobron, David
Subject: Re: Mysterious crash in NSRunLoop, using libobjc2 on Linux
Date: Tue, 12 Dec 2017 15:30:59 +0000

> Throwing with `throw` instead of `@throw` should do that: the exception will 
> be thrown by the C++ runtime, not the Objective-C one.  I thought your 
> problem was the other way around though, so it might be that you need a c++ 
> destructor to force the ObjC runtime to turn it into a C++ exception for 
> delivery to C++.

I tweaked my code a bit.  I now have an ObjC class in a .m file that throws an 
exception like this:

- (void)poke
{
  [NSException raise:@"Exception" format:@"Exception"];
}

I call this from a .m file, inside an NS_HANDLER, and then re-raise the 
exception.  The goal here is to pass the NSException through a plain ObjC frame:

- (void)poke
{
    NS_DURING
      [_oc poke];
    NS_HANDLER
      NSLog(@"Caught second exception");
      [localException raise];
    NS_ENDHANDLER
}

Finally, I call this from a .mm file, inside a C++ class method:

void tryCpp() {
    Tester *t = [[Tester new] autorelease];
    try {
      try {
        NSLog(@"tryCpp starting");
        [t poke];
      } catch(NSException *e) {
        NSLog(@"tryCpp aught ObjC exception");
        throw e;
      }
    } catch(...) {
      NSLog(@"tryCpp caught outer exception");
    }
  }

The goal here is to do what you suggested above, namely, force the ObjC runtime 
to turn the NSException into a C++ exception for delivery to the tryCpp method, 
which is a plain C++ instance method.  But the debug output (copied below) 
suggests that is not happening: all of the exception personalities are of class 
GNUCOBJC.  Am I missing a step here, or not understanding the way exception 
personalities are passed through frames?  I'm still learning this, so maybe I'm 
missing something obvious.

Thanks,

--David

Debug output:

2017-12-12 15:28:01.629 RunTest[19196:19196] tryCpp starting
Throwing 0x17cf610
New personality function called 0x17db3a0
Class: GNUCOBJC
LSDA: 0x40405c
Search phase...
Filter: 1
Class name: NSException
0x7f3316d04de8 type: 1
found handler for NSException
handler: 4
Found handler! 4
New personality function called 0x17db3a0
Class: GNUCOBJC
LSDA: 0x40405c
Phase 2: Fight!
Installing context, selector 1
Beginning catch 0x17db3a0
objc catch
2017-12-12 15:28:01.629 RunTest[19196:19196] Caught second exception
Throwing 0x17cf610
New personality function called 0x17db440
Class: GNUCOBJC
LSDA: 0x40405c
Search phase...
handler: 1
New personality function called 0x17db440
Class: GNUCOBJC
LSDA: 0x40405c
Phase 2: Fight!
Not the handler frame, looking up the cleanup again
handler! 1 0
Installing cleanup...
Installing context, selector 0
Ending catch
New personality function called 0x17db440
Class: GNUCOBJC
LSDA: 0x40405c
Phase 2: Fight!
Not the handler frame, looking up the cleanup again
2017-12-12 15:28:01.629 RunTest[19196:19196] tryCpp aught ObjC exception
Throwing 0x17cf610
2017-12-12 15:28:01.629 RunTest[19196:19196] tryCpp caught outer exception





reply via email to

[Prev in Thread] Current Thread [Next in Thread]