Skip to content

Instantly share code, notes, and snippets.

@charlesmchen
Created September 19, 2012 13:46
Show Gist options
  • Save charlesmchen/3749768 to your computer and use it in GitHub Desktop.
Save charlesmchen/3749768 to your computer and use it in GitHub Desktop.
#define FLURRYLOGERROR(id, msg, err) [FlurryAnalytics logError:id message:msg error:err]
namespace
{
void logUncaughtException(const std::string& type,
const std::string& message)
{
#ifdef DEBUG
NSLog(@"exception error\n%s %s",type.c_str(), message.c_str());
#endif
#ifdef FLURRYLOGGING
NSString * t = [NSString stringWithUTF8String:type.c_str()];
NSString * m = [NSString stringWithUTF8String:message.c_str()];
//Flurry's logging calls are async, thus
//we give them time to complete and either log to disk
//or network before we exit.
FLURRYLOGERROR(t, m, nil);
sleep(1);
#endif
}
}
int main(int argc, char *argv[])
{
int retVal;
try
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
retVal = UIApplicationMain(argc, argv, nil, nil);
[pool release];
}
catch (const std::string& s)
{
logUncaughtException("stringException", s);
}
catch (const boost::exception& e)
{
logUncaughtException("boostException", boost::diagnostic_information(e));
}
catch (const std::exception& e)
{
logUncaughtException("stlException", e.what());
}
catch(NSException* ex)
{
// Oddly, we can catch exceptions raised via [NSException raise] and @throw
// in C++ style exception handlers.
// Since these are logged with callstacks in test flight, we just rethrow.
throw;
}
catch (...)
{
logUncaughtException("unknownException", "");
//We let test flight try to make sense of this as well, so we rethrow.
throw;
}
return retVal;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment