c# - System.Net.WebException not intercepted on Windows Phone 8 -
i trying call web service using restsharp (this has done wp8 onwards).
this triggered method:
private async void postrest() { string getsyncservice = "myservice"; var client = new restclient(ip); var request = new restrequest(getsyncservice, method.post); request.requestformat = dataformat.json; jsonobject jsongenericrequest = new jsonobject(); jsongenericrequest.add("companyid", "123"); jsongenericrequest.add("token", "123"); ... request.addparameter("genmobilerequest", jsongenericrequest); request.addheader("access-control-allow-methods", "post"); request.addheader("content-type", "application/json; charset=utf-8"); request.addheader("accept", "application/json"); try { // easy async support client.executeasync(request, response => { console.writeline("response content: " + response.content); if (response.responsestatus == responsestatus.completed) { messagebox.show("errormsg: " + response.errormessage); } }); } catch (system.net.webexception ex) { messagebox.show(" " + ex.innerexception.tostring()); } }
on log getting exception:
an exception of type 'system.net.webexception' occurred in system.windows.ni.dll , wasn't handled before managed/native boundary
i cant keep information in handler
// code execute on unhandled exceptions private void application_unhandledexception(object sender, applicationunhandledexceptioneventargs e) { console.writeline(" ---application_unhandledexception---"); if (debugger.isattached) { // unhandled exception has occurred; break debugger debugger.break(); } }
how can more info wrong?
any additional information on proper way call ws appreciated.
thanks
reason exceptions async void method can’t caught catch.
"async void methods have different error-handling semantics. when exception thrown out of async task or async task method, exception captured , placed on task object. async void methods, there no task object, exceptions thrown out of async void method raised directly on synchronizationcontext active when async void method started"
the error async void method needs changed async task method instead.
Comments
Post a Comment