[mono-android] Exceptions not getting caught on thread

klimaye klimaye at gmail.com
Mon Nov 21 11:15:21 EST 2011


I am trying to download json data in a background task. I am noticing that
when I get the following exception, the control never comes in the
ContinueWith block and the progress dialog is stuck making the app unusable.
I have tried using the ThreadPool but it has the same effect. If I throw an
exception myself in the action, it gets caught but not the one below. Any
thoughts/ideas/pointers?

I/mono    ( 8196): Stacktrace:
I/mono    ( 8196):
I/mono    ( 8196):   at Newtonsoft.Json.Utilities.StringBuffer..ctor (int)
<0x0001f>
I/mono    ( 8196):   at Newtonsoft.Json.JsonTextReader..ctor
(System.IO.TextReader) <0x00057>
I/mono    ( 8196):   at Newtonsoft.Json.JsonConvert.DeserializeObject
(string,System.Type,Newtonsoft.Json.JsonSerializerSettings) <0x00063>
I/mono    ( 8196):   at Newtonsoft.Json.JsonConvert.DeserializeObject
(string,System.Type,Newtonsoft.Json.JsonConverter[]) <0x00077>
I/mono    ( 8196):   at Newtonsoft.Json.JsonConvert.DeserializeObject<T>
(string,Newtonsoft.Json.JsonConverter[]) <0x0002b>
D/dalvikvm(  285): GC_EXPLICIT freed 18K, 8% free 6814K/7367K, paused
7ms+2ms
D/dalvikvm( 5766): GC_EXPLICIT freed 134K, 7% free 7346K/7815K, paused
7ms+2ms

With the following code

myProgressDialog = MyProgressDialog.Show(this, "Synching Data", "Synching");
            var task1 = new Task<bool>(() => DoSync(strategy, pin));
            task1.ContinueWith(t =>
            {
                var result1 = t.Result;
                if (t.Exception != null)
                {
                    var ae = t.Exception;
                    Log.Error("error", " {0}, {1}", ae.Message,
ae.StackTrace);
                    result1 = false;
                }
                RunOnUiThread(() =>
                {
                    _viewModel.SetSyncSuccess(result1);
                    myProgressDialog.Dismiss();
                    ShowDialog(DIALOG_SYNC_RESULT);
                });
            });
            task1.Start();

--
View this message in context: http://mono-for-android.1047100.n5.nabble.com/Exceptions-not-getting-caught-on-thread-tp5010939p5010939.html
Sent from the Mono for Android mailing list archive at Nabble.com.


More information about the Monodroid mailing list