The Labs \ Source Viewer \ SSCLI \ System.Net \ WebException

  1. //------------------------------------------------------------------------------
  2. // <copyright file="WebException.cs" company="Microsoft">
  3. //
  4. // Copyright (c) 2006 Microsoft Corporation. All rights reserved.
  5. //
  6. // The use and distribution terms for this software are contained in the file
  7. // named license.txt, which can be found in the root of this distribution.
  8. // By using this software in any fashion, you are agreeing to be bound by the
  9. // terms of this license.
  10. //
  11. // You must not remove this notice, or any other, from this software.
  12. //
  13. // </copyright>
  14. //------------------------------------------------------------------------------
  15. namespace System.Net
  16. {
  17.     using System;
  18.     using System.Runtime.Serialization;
  19.     using System.Security.Permissions;
  20.    
  21. /*++
  22.     Abstract:
  23.         Contains the defintion for the WebException object. This is a subclass of
  24.         Exception that contains a WebExceptionStatus and possible a reference to a
  25.         WebResponse.
  26.     --*/   
  27.    
  28.    
  29.    
  30.     /// <devdoc>
  31.     /// <para>
  32.     /// Provides network communication exceptions to the application.
  33.     ///
  34.     /// This is the exception that is thrown by WebRequests when something untoward
  35.     /// happens. It's a subclass of WebException that contains a WebExceptionStatus and possibly
  36.     /// a reference to a WebResponse. The WebResponse is only present if we actually
  37.     /// have a response from the remote server.
  38.     /// </para>
  39.     /// </devdoc>
  40.     [Serializable()]
  41.     public class WebException : InvalidOperationException, ISerializable
  42.     {
  43.        
  44.         private WebExceptionStatus m_Status = WebExceptionStatus.UnknownError;
  45.         //Should be changed to GeneralFailure;
  46.         private WebResponse m_Response;
  47.         [NonSerialized()]
  48.         private WebExceptionInternalStatus m_InternalStatus = WebExceptionInternalStatus.RequestFatal;
  49.        
  50.        
  51.         /// <devdoc>
  52.         /// <para>
  53.         /// Creates a new instance of the <see cref='System.Net.WebException'/>
  54.         /// class with the default status
  55.         /// <see langword='Error'/> from the
  56.         /// <see cref='System.Net.WebExceptionStatus'/> values.
  57.         /// </para>
  58.         /// </devdoc>
  59.         public WebException()
  60.         {
  61.            
  62.         }
  63.        
  64.        
  65.         /// <devdoc>
  66.         /// <para>
  67.         /// Creates a new instance of the <see cref='System.Net.WebException'/> class with the specified error
  68.         /// message.
  69.         /// </para>
  70.         /// </devdoc>
  71.         public WebException(string message) : this(message, null)
  72.         {
  73.         }
  74.        
  75.        
  76.         /// <devdoc>
  77.         /// <para>
  78.         /// Creates a new instance of the <see cref='System.Net.WebException'/> class with the specified error
  79.         /// message and nested exception.
  80.         ///
  81.         /// Message - Message string for exception.
  82.         /// InnerException - Exception that caused this exception.
  83.         ///
  84.         /// </para>
  85.         /// </devdoc>
  86.         public WebException(string message, Exception innerException) : base(message, innerException)
  87.         {
  88.         }
  89.        
  90.         public WebException(string message, WebExceptionStatus status) : this(message, null, status, null)
  91.         {
  92.         }
  93.        
  94.        
  95.         /// <devdoc>
  96.         /// <para>
  97.         /// Creates a new instance of the <see cref='System.Net.WebException'/> class with the specified error
  98.         /// message and status.
  99.         ///
  100.         /// Message - Message string for exception.
  101.         /// Status - Network status of exception
  102.         /// </para>
  103.         /// </devdoc>
  104.         internal WebException(string message, WebExceptionStatus status, WebExceptionInternalStatus internalStatus, Exception innerException) : this(message, innerException, status, null, internalStatus)
  105.         {
  106.         }
  107.        
  108.         /// <devdoc>
  109.         /// <para>
  110.         /// Creates a new instance of the <see cref='System.Net.WebException'/> class with the specified error
  111.         /// message, nested exception, status and response.
  112.         ///
  113.         /// Message - Message string for exception.
  114.         /// InnerException - The exception that caused this one.
  115.         /// Status - Network status of exception
  116.         /// Response - The WebResponse we have.
  117.         /// </para>
  118.         /// </devdoc>
  119.         public WebException(string message, Exception innerException, WebExceptionStatus status, WebResponse response) : this(message, null, innerException, status, response)
  120.         {
  121.         }
  122.        
  123.         internal WebException(string message, string data, Exception innerException, WebExceptionStatus status, WebResponse response) : base(message + (data != null ? ": '" + data + "'" : ""), innerException)
  124.         {
  125.             m_Status = status;
  126.             m_Response = response;
  127.         }
  128.        
  129.         internal WebException(string message, Exception innerException, WebExceptionStatus status, WebResponse response, WebExceptionInternalStatus internalStatus) : this(message, null, innerException, status, response, internalStatus)
  130.         {
  131.         }
  132.        
  133.         internal WebException(string message, string data, Exception innerException, WebExceptionStatus status, WebResponse response, WebExceptionInternalStatus internalStatus) : base(message + (data != null ? ": '" + data + "'" : ""), innerException)
  134.         {
  135.             m_Status = status;
  136.             m_Response = response;
  137.             m_InternalStatus = internalStatus;
  138.         }
  139.        
  140.        
  141.         protected WebException(SerializationInfo serializationInfo, StreamingContext streamingContext) : base(serializationInfo, streamingContext)
  142.         {
  143.             // m_Status = (WebExceptionStatus)serializationInfo.GetInt32("Status");
  144.             // m_InternalStatus = (WebExceptionInternalStatus)serializationInfo.GetInt32("InternalStatus");
  145.         }
  146.        
  147.         /// <internalonly/>
  148.        
  149.         [SecurityPermission(SecurityAction.LinkDemand, Flags = SecurityPermissionFlag.SerializationFormatter)]
  150.         void ISerializable.GetObjectData(SerializationInfo serializationInfo, StreamingContext streamingContext)
  151.         {
  152.             GetObjectData(serializationInfo, streamingContext);
  153.         }
  154.        
  155.        
  156.         [SecurityPermissionAttribute(SecurityAction.LinkDemand, Flags = SecurityPermissionFlag.SerializationFormatter)]
  157.         public override void GetObjectData(SerializationInfo serializationInfo, StreamingContext streamingContext)
  158.         {
  159.             base.GetObjectData(serializationInfo, streamingContext);
  160.             //serializationInfo.AddValue("Status", (int)m_Status, typeof(int));
  161.             //serializationInfo.AddValue("InternalStatus", (int)m_InternalStatus, typeof(int));
  162.         }
  163.        
  164.         /// <devdoc>
  165.         /// <para>
  166.         /// Gets the status of the response.
  167.         /// </para>
  168.         /// </devdoc>
  169.         public WebExceptionStatus Status {
  170.             get { return m_Status; }
  171.         }
  172.        
  173.        
  174.         /// <devdoc>
  175.         /// <para>
  176.         /// Gets the error message returned from the remote host.
  177.         /// </para>
  178.         /// </devdoc>
  179.         public WebResponse Response {
  180.             get { return m_Response; }
  181.         }
  182.        
  183.         /// <devdoc>
  184.         /// <para>
  185.         /// Gets the error message returned from the remote host.
  186.         /// </para>
  187.         /// </devdoc>
  188.         internal WebExceptionInternalStatus InternalStatus {
  189.             get { return m_InternalStatus; }
  190.         }
  191.        
  192.     }
  193.     // class WebException
  194.     internal enum WebExceptionInternalStatus
  195.     {
  196.         RequestFatal = 0,
  197.         ServicePointFatal = 1,
  198.         Recoverable = 2,
  199.         Isolated = 3
  200.     }
  201.    
  202.    
  203. }
  204. // namespace System.Net

Developer Fusion