[WP8.1]Create WebException from Windows.Networking.Sockets.SocketErrorStatus in Windows Phone 8.1 RRS feed

  • Question

  • Hi All,

    The Complete Application is developed using HttpWebRequest and HttpClient. We handled errors based on WebException & WebResponse. Recently one of the client requirement is to use StreamSocket API.

    I have Implemented the API fine, but the exceptions are different when compared StreamSocket vs HttpWebRequest exceptions. So I just want to throw same HttpWebRequest exceptions based on SocketErrorStatus.

    Do We have API to create WebException from Windows.Networking.Sockets.SocketErrorStatus [OR] any option to use existing error handling code?


    Pallam Madhukar Windows Phone Developer

    Thursday, April 7, 2016 6:57 AM


  • Hi Pallam Madhukar,

    >>”So I just want to throw same HttpWebRequest exceptions based on SocketErrorStatus.”

    In my opinion, when you use StreamSockets APIs, you would need to handle exceptions of it. For example, you could use “try/catch/finally” to catch exception. Then when you catch the exception, you could throw a new instance of the WebException class with the specified error message and nested exception in “catch” scope.

                catch (SocketException ex)
                    throw new WebException("Unable to locate the Server",ex);

    You could use "WebException Constructor (String, Exception)" to throw a new instance of the WebException.

    Best Regards,

    Xavier Eoro

    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Friday, April 8, 2016 6:14 AM