svhawks / EasyFacebook

This library is deprecated. Facebook has improved their SDK drastically since then.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Impossible to catch Exception from openFromAccessTokenData

blaues0cke opened this issue · comments

My app is reporting crashes raised by EasyFacebook. I digged into the code and found out that the crash is forced by this code:

    if (raiseException) {
        [[NSException exceptionWithName:FBInvalidOperationException
                                 reason:@"FBSession: cannot open a session from token data from its current state"
                               userInfo:nil]
         raise];
    } else {
        return NO;
    }

The NSException will be thorwn since it is called like this:

- (BOOL)openFromAccessTokenData:(FBAccessTokenData *)accessTokenData completionHandler:(FBSessionStateHandler)handler {
return [self openFromAccessTokenData:accessTokenData
                   completionHandler:handler
        raiseExceptionIfInvalidState:YES];

}

I am not able to catch this Exception since the code runs in subthread. How could I fix this without changing raiseExceptionIfInvalidState:YES to raiseExceptionIfInvalidState:NO?

FYI. A workaround is this code. Allows me to show an error message instead of crashing the whole app:

// TODO : Need to support more states (possibly as simple as !isOpen) in the case that this is g_activeSession,
// and ONLY in that case.
if (!(self.state == FBSessionStateCreated)) {
    if (raiseException) {

        [[NSNotificationCenter defaultCenter] postNotificationName:@"EasyFacebookException" object:nil];

        return NO;
        [[NSException exceptionWithName:FBInvalidOperationException
                                 reason:@"FBSession: cannot open a session from token data from its current state"
                               userInfo:nil]
         raise];
    } else {
        return NO;
    }
}