Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

handling ObjC exceptions in monotouch

Sometimes I'm getting exception from inside objective-c code. in my example these exceptions are not critical and I want the app to keep working. The question is how do I handle these exceptions?

for example, my app crashes time to time while I'm using GeoCoder class. I don't really care if geocoder failed to geocode location and would like to keep my app alive. including geocoder calls in try-catch blocks doesn't solve the problem.

Any help will be appreciated!

like image 733
Alex D Avatar asked May 11 '12 07:05

Alex D


1 Answers

MonoTouch tries to a certain extent to convert ObjC exceptions into managed exceptions. This is done by adding an unhandled exception handler for ObjC exceptions, and in there throw a managed exception. This works on secondary threads, but not on the main thread, because iOS has a try-catch handler in its main run loop, which will kill your app if any exceptions reaches it (in other words the exception is handled, so it will never reach MonoTouch' unhandled exception handler).

The best way is to avoid the ObjC exceptions in the first place (Apple's documentation states that ObjC exceptions should only be used for truly exceptional circumstances, since they have a number of problems - memory leaks is quite common for instance).

It is obviously not possible to avoid all ObjC exceptions, so we try to find workarounds for those cases where it still happens. The best way to get this done for your particular case is for you to create a complete test case and open a bug report here: http://bugzilla.xamarin.com, attaching the test case.

like image 71
Rolf Bjarne Kvinge Avatar answered Oct 22 '22 09:10

Rolf Bjarne Kvinge