WebException.cs 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. //
  2. // System.Net.WebException.cs
  3. //
  4. // Author:
  5. // Lawrence Pit ([email protected])
  6. //
  7. using System.Runtime.Serialization;
  8. namespace System.Net
  9. {
  10. [Serializable]
  11. public class WebException : InvalidOperationException, ISerializable
  12. {
  13. private WebResponse response;
  14. private WebExceptionStatus status = WebExceptionStatus.RequestCanceled;
  15. // Constructors
  16. public WebException () : base ()
  17. {
  18. }
  19. public WebException (string message) : base (message)
  20. {
  21. }
  22. protected WebException (SerializationInfo info,
  23. StreamingContext context)
  24. : base (info, context)
  25. {
  26. status = (WebExceptionStatus) info.GetInt32 ("web_status");
  27. response = (WebResponse) info.GetValue ("web_response", typeof (WebResponse));
  28. }
  29. public WebException (string message, Exception innerException)
  30. : base (message, innerException)
  31. {
  32. }
  33. public WebException (string message, WebExceptionStatus status)
  34. : base (message)
  35. {
  36. this.status = status;
  37. }
  38. public WebException(string message,
  39. Exception innerException,
  40. WebExceptionStatus status,
  41. WebResponse response)
  42. : base (message, innerException)
  43. {
  44. this.status = status;
  45. this.response = response;
  46. }
  47. // Properties
  48. public WebResponse Response {
  49. get { return this.response; }
  50. }
  51. public WebExceptionStatus Status {
  52. get { return this.status; }
  53. }
  54. // Methods
  55. void ISerializable.GetObjectData (SerializationInfo info, StreamingContext context)
  56. {
  57. base.GetObjectData (info, context);
  58. info.AddValue ("web_status", (int) status, typeof (int));
  59. info.AddValue ("web_response", response, typeof (WebResponse));
  60. }
  61. }
  62. }