[mono-android] Catch all the exceptions
Jonathan Pryor
jonp at xamarin.com
Mon Jan 23 21:10:06 UTC 2012
On Jan 23, 2012, at 7:50 AM, PVoLan wrote:
> I want to handle all the exceptions in my application and send them to my
> server, collecting statistics info. This looks like a trivial task, but I've
> got some problems.
Unfortunately we don't have a good answer at this time.
The primary problem is that there are no unhandled exceptions, at least not when Android code is the caller (e.g. if you're on the main UI thread, Activity.OnCreate() is called, etc.). The reason for this is that every place that Android calls into managed code is wrapped in a try/catch, thus "handling" the exception.
The "good" news is that we do provide a way to "hook" into when an exception is transitioning from the managed -> Android stacks:
http://androidapi.xamarin.com/?link=E%3aAndroid.Runtime.AndroidEnvironment.UnhandledExceptionRaiser
The "bad" news is that there's currently no way to say that this is actually an "unhandled" exception. It's entirely possible to have Android (1) call into C# (2) which calls into Android (3) which calls into C# (4), and (4) throws an exception which (2) catches. AndroidEnvironment.UnhandledExceptionRaiser will be raised at (4), but there's no way to know when (4) is invoked that the exception will be caught at (2). :-(
This is something we'll need to address in a future release.
- Jon
More information about the Monodroid
mailing list