System.Net WebException is an exception class in C# that is used to handle exceptions that occur when a communication error occurs while sending or receiving HTTP requests or responses. This exception is thrown by the WebRequest, HttpWebRequest, and FtpWebRequest classes.
Example 1: If the server returns a 404 Not Found error while requesting a resource, a WebException is thrown.
using (WebResponse response = request.GetResponse()) { // Do something with response } } catch (WebException ex) { Console.WriteLine("Exception caught: " + ex.Message); }
Package library: System.dll.
C# (CSharp) System.Net WebException - 48 examples found. These are the top rated real world C# (CSharp) examples of System.Net.WebException extracted from open source projects. You can rate examples to help us improve the quality of examples.