Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Alternative to NSSetUncaughtExceptionHandler on iPhone

I'm trying to make a general error handler for an iPhone app that brings the user to a recovery screen whenever any general error is thrown in the application without putting a try/catch block around every single method in the application.

Using NSSetUncaughtExceptionHandler doesn't work because the application terminates after the handler is run.

Is there any way to change this behavior, or use any other handler that will catch exceptions in general and not cause the application to exit afterward?

And please, no non-answers about whether it's a good or bad idea.

like image 954
Ed Marty Avatar asked Jan 20 '10 17:01

Ed Marty


1 Answers

The original poster has probably solved his problem by now. However, for anyone who comes across this in the future...

Matt Gallagher wrote an excellent post on catching unhandled exceptions and signals a few months after this question was posted. I find it to be much more informative than the answer referenced above by Scott.

In particular, Matt's post describes how to attempt a recovery (if appropriate) that allows your app to keep running, and even displays a UIAlertView with error information if you want (hint: it involves creating a new run loop).

like image 170
Clint Harris Avatar answered Sep 24 '22 02:09

Clint Harris