We’re developing a cross platform application for iOS, Android and WP7 by using MVVMCross framework and I’m missing a method in MvxApplication that I can override which can serves as the platform neutral unhandled exception handler (which gets called by the platform specific ones).
So the question is what is the suggested way to handle exceptions generally and during an async call in a MVVMCross application?
Thanks,
Attila
For genuinely unexpected exceptions (crashes!) then this question is currently unanswered: see crash reporting in MonoTouch and MonoDroid
However, for a suggestion on how you might handle exceptions during an async call, then take a look at the BestSellers example: MvvmCross BestSellers Sample
BestSellers uses 2 techniques that I find I’ve used quite a lot in MvvmCross applications:
At a more detailed level, what BestSellers does is:
Each ViewModel uses a direct call to a webservice for book information. For example the Category List is constructed as:
where GeneralAsyncLoad is defined in a shared BaseViewModel:
The ReportError method within the above exception handler uses an injected object – an
IErrorReporter.This injected object is initialised as a singleton during App construction – see
ErrorApplicationObjectin App.csDuring their construction and setup, the UI projects all subscribe to events from that same singleton – but using an
IErrorSourceinterface instead orIErrorReporter.This then allows each platform to display it’s own error display – e.g.:
Obviously, if you need error handling as well as error displaying – e.g. if you want to retry the asynchronous operation or if you want to load an offline copy of data instead – then you can add this to your error handling within the ViewModel and the BaseViewModel.