WebException.cs 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. //
  2. // System.Net.WebException.cs
  3. //
  4. // Author:
  5. // Lawrence Pit ([email protected])
  6. //
  7. //
  8. // Permission is hereby granted, free of charge, to any person obtaining
  9. // a copy of this software and associated documentation files (the
  10. // "Software"), to deal in the Software without restriction, including
  11. // without limitation the rights to use, copy, modify, merge, publish,
  12. // distribute, sublicense, and/or sell copies of the Software, and to
  13. // permit persons to whom the Software is furnished to do so, subject to
  14. // the following conditions:
  15. //
  16. // The above copyright notice and this permission notice shall be
  17. // included in all copies or substantial portions of the Software.
  18. //
  19. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  20. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  21. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  22. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  23. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  24. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  25. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  26. //
  27. using System.Runtime.Serialization;
  28. namespace System.Net
  29. {
  30. [Serializable]
  31. public class WebException : InvalidOperationException, ISerializable
  32. {
  33. private WebResponse response;
  34. private WebExceptionStatus status = WebExceptionStatus.RequestCanceled;
  35. // Constructors
  36. public WebException () : base ()
  37. {
  38. }
  39. public WebException (string message) : base (message)
  40. {
  41. }
  42. protected WebException (SerializationInfo info,
  43. StreamingContext context)
  44. : base (info, context)
  45. {
  46. status = (WebExceptionStatus) info.GetInt32 ("web_status");
  47. response = (WebResponse) info.GetValue ("web_response", typeof (WebResponse));
  48. }
  49. public WebException (string message, Exception innerException)
  50. : base (message, innerException)
  51. {
  52. }
  53. public WebException (string message, WebExceptionStatus status)
  54. : base (message)
  55. {
  56. this.status = status;
  57. }
  58. public WebException(string message,
  59. Exception innerException,
  60. WebExceptionStatus status,
  61. WebResponse response)
  62. : base (message, innerException)
  63. {
  64. this.status = status;
  65. this.response = response;
  66. }
  67. // Properties
  68. public WebResponse Response {
  69. get { return this.response; }
  70. }
  71. public WebExceptionStatus Status {
  72. get { return this.status; }
  73. }
  74. // Methods
  75. void ISerializable.GetObjectData (SerializationInfo info, StreamingContext context)
  76. {
  77. base.GetObjectData (info, context);
  78. info.AddValue ("web_status", (int) status, typeof (int));
  79. info.AddValue ("web_response", response, typeof (WebResponse));
  80. }
  81. }
  82. }