Xamarin System.Net.WebException missing WebExceptionStatus.NameResolutionFailure

╄→尐↘猪︶ㄣ 提交于 2019-12-23 22:20:57

问题


I have an exception I can't handle properly in Xamarin.Forms due to a missing member in the WebExceptionStatus enumeration, namely the NameResolutionFailure member.

Does anyone know how I can properly handle the exception in this specific case?


回答1:


When looking at a previous version of the WebExceptionStatus enumeration, the NameResolutionFailure member is not supported in a PCL.

What you can do to handle this issue is as follows:

case (System.Net.WebExceptionStatus)1:
    // your code

Or:

catch (System.Net.WebException ex)
{
    if ((int)ex.Status == 1)
        // your code
)

I tested this by simply throwing a new WebException like this:

throw new System.Net.WebException("Test", (System.Net.WebExceptionStatus)1);

Which, as I thought, returned an exception with NameResolutionFailure being the StatusCode.



来源:https://stackoverflow.com/questions/41413172/xamarin-system-net-webexception-missing-webexceptionstatus-nameresolutionfailure

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!