Indeed looks like m4a internally is using a Task to invoke OnCreate. Perhaps it is by design that exceptions aren't handled when invoking OnCreate and applications is stopped if an unhandled exception occurs.
Miha -----Original Message----- From: [email protected] [mailto:[email protected]] On Behalf Of Stephan Steiner Sent: Sunday, September 30, 2012 5:39 PM To: [email protected] Subject: [mono-android] Avoidable TPF error in M4A Hi Here's a little bug I found in M4A (both 4.2.4 and the 4.2.7 beta) and a way to work around it: Put the following in your app's main activity's OnCreate int resourceId = Application.Context.Resources.GetIdentifier("some_non_existing_identifier", "string", Application.Context.PackageName); string myString = Application.Context.Resources.GetString(resourceId); And debug the app. You'll get an uncaught exception on the second line (resourceId will be 0, so the resource cannot be found), press continue twice, and debugging will stop and M4A will show you a TPF error about an uncaught Task Exception. This can easily be avoided if all Tasks that M4A uses itself are waited upon, or followed by a task that handles exceptions. For instance, this is what I'm using inside my M4A projects (derived from a similar class I'm using for my desktop projects): public class MyTaskFactory { public static Task CreateTask(Action action) { Task myTask = new Task(action); addContinuationTask(myTask); return myTask; } public static Task CreateTask(Action action, CancellationToken token) { Task myTask = new Task(action, token); addContinuationTask(myTask); return myTask; } private static void addContinuationTask(Task myTask) { Task continuationTask = myTask.ContinueWith(t => { foreach (var e in t.Exception.Flatten().InnerExceptions) processException(e); }, TaskContinuationOptions.OnlyOnFaulted); Task errorTask = myTask.ContinueWith(t => { AndroidLogModel.Model.AddLogMessage("TaskFactory", "Task cancelled", 5); }, TaskContinuationOptions.OnlyOnCanceled); } protected static void processException(Exception e) { AndroidLogModel.Model.AddLogMessage("TaskFactory", "Task exception: " + e.Message + " at " + e.StackTrace, 4); } } Instead of calling Task.Factory.Create, you'd create your tasks using MyTaskFactory.CreateTask. -- View this message in context: http://mono-for-android.1047100.n5.nabble.com/Avoidable-TPF-error-in-M4A-tp5712017.html Sent from the Mono for Android mailing list archive at Nabble.com. _______________________________________________ Monodroid mailing list [email protected] UNSUBSCRIBE INFORMATION: http://lists.ximian.com/mailman/listinfo/monodroid _______________________________________________ Monodroid mailing list [email protected] UNSUBSCRIBE INFORMATION: http://lists.ximian.com/mailman/listinfo/monodroid
