Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Monotouch Global Exception handling

I am having a nasty bug show up in the wild, and I can't put my finger on it. Is there a way to have a Global Try/Catch block, or a way to handle any exception that is unhanded in Monotouch.

Can I just wrap UIApplication.Main(args) in a try catch?

After the exception is caught, Id like to show a UIAlertView to display the results.

Any help?

like image 731
Chris Kooken Avatar asked Jan 28 '11 16:01

Chris Kooken


People also ask

What is global exception handling?

The Global Exception Handler is a type of workflow designed to determine the project's behavior when encountering an execution error. Only one Global Exception Handler can be set per automation project.

What is global exception handling in C#?

An ExceptionFilterAttribute is used to collect unhandled exceptions. You can register it as a global filter, and it will function as a global exception handler. Another option is to use a custom middleware designed to do nothing but catch unhandled exceptions.

How do you handle exceptions in Rails?

Exception handling in Ruby on Rails is similar to exception handling in Ruby. Which means, we enclose the code that could raise an exception in a begin/end block and use rescue clauses to tell Ruby the types of exceptions we want to handle.


1 Answers

You can wrap UIApplication.Main (args) in a try {} catch {} but you will not be able to show a UIAlertView at that point, since we've unwound the entire stack including all the UI. What you could do is log the exception to a crash file in the Documents folder of your application bundle, and show that on the next launch or upload it to a web service.

The Exceptioneer guys were working on MonoTouch support as well, which might be worth looking into.

like image 200
Geoff Norton Avatar answered Sep 28 '22 00:09

Geoff Norton