I have an ios app in which I am already using Crittercism. It reports the exceptions perfectly.
My problem is that I also want those exceptions to be logged to my backend server.
I have tried a lot of things to make it happen but to no avail. Here are the list of things I tried:
NSSetUncaughtExceptionHandler(&myExceptionHandler);If I do this, the exception is not reported in Crittercism.
NSSetUncaughtExceptionHandler(&myExceptionHandler);Send the exception to my server.
Then call the constructor of Crittercism in myExceptionHandler function and rethrow the exception. Doesn't work.
Call the constructor of Crittercism followed by NSSetUncaughtExceptionHandler(&myExceptionHandler); and in myExceptionHandler call [Crittercism logHandledException:exception];. Doesn't work either.
In my exception handler serialize the exception object and store it in user preferences. When the user restarts the app, call [Crittercism logHandledException:exception]; and then send the exception to my backend server. Problem with this was, I was not able to deserialize the string to exception object. I couldn't put the stack trace in NSString form into my exception object.
Some things I could have tried:
Let the crittercism handle the exception and then on next restart, crittercismDidCrashOnLastLoad will be called - but do I have the exception info present or can I access it from somewhere.
I may not need to deserialize the string to exception object. I believe Crittercism is also changing the exception into a json object and sending this json object to its servers. But I am not able to find out which functions to use to send a custom json object to crittercism.
Can someone guide me on how to proceed?
I have found the solution to this. Firstly init the crittercism object using
[Crittercism initWithAppID:crittercismAppID andKey:crittercismKey andSecret:crittercismSecret];
Now define
NSUncaughtExceptionHandler* crittercismHandler = NSGetUncaughtExceptionHandler();//You have stored the reference to the crittercism function that was going to get called in the event of an exception
Then,
NSSetUncaughtExceptionHandler(&myHandledException);//Set the handler to your custom function
In your custom function, do whatever you want to do with your exception and then call
NSSetUncaughtExceptionHandler(crittercismHandler);//this will re-set the exception handler to the one of crittercism
Call
crittercismHandler(exception);//This will send the exception to crittercism servers.
You can do similar things for signals.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With