Win32Exception.cs 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. //
  2. // System.ComponentModel.Win32Exception.cs
  3. //
  4. // Author:
  5. // Dick Porter ([email protected])
  6. //
  7. // (C) 2002 Ximian, Inc. http://www.ximian.com
  8. //
  9. using System.Security;
  10. using System.Runtime.InteropServices;
  11. using System.Runtime.Serialization;
  12. using System.Collections;
  13. using System.Globalization;
  14. namespace System.ComponentModel
  15. {
  16. [Serializable, SuppressUnmanagedCodeSecurity]
  17. public class Win32Exception : ExternalException
  18. {
  19. private int native_error_code;
  20. public Win32Exception ()
  21. : base (W32ErrorMessage(Marshal.GetLastWin32Error()),
  22. Marshal.GetLastWin32Error()) {
  23. native_error_code=Marshal.GetLastWin32Error();
  24. }
  25. public Win32Exception(int error)
  26. : base (W32ErrorMessage(error), error) {
  27. native_error_code=error;
  28. }
  29. public Win32Exception(int error, string message)
  30. : base (message, error) {
  31. native_error_code=error;
  32. }
  33. protected Win32Exception(SerializationInfo info,
  34. StreamingContext context)
  35. : base (info, context) {
  36. }
  37. public int NativeErrorCode {
  38. get {
  39. return(native_error_code);
  40. }
  41. }
  42. public override void GetObjectData(SerializationInfo info, StreamingContext context)
  43. {
  44. if (info==null)
  45. throw new ArgumentNullException ("info");
  46. info.AddValue ("native_error_code", native_error_code);
  47. base.GetObjectData (info, context);
  48. }
  49. private static Hashtable w32_errors = new Hashtable();
  50. /* Initialise the list of error strings */
  51. static Win32Exception() {
  52. /* No need to list everything, just the ones
  53. * the runtime can throw. A list of the errors
  54. * can be found in class System.IO.MonoIOError.
  55. */
  56. w32_errors.Add(2,
  57. Locale.GetText("Cannot find the specified file"));
  58. w32_errors.Add(10004,
  59. Locale.GetText("interrupted"));
  60. w32_errors.Add(10013,
  61. Locale.GetText("Access denied"));
  62. w32_errors.Add(10022,
  63. Locale.GetText("Invalid arguments"));
  64. w32_errors.Add(10035,
  65. Locale.GetText("Operation on non-blocking socket would block"));
  66. w32_errors.Add(10036,
  67. Locale.GetText("Operation in progress"));
  68. w32_errors.Add(10038,
  69. Locale.GetText("The descriptor is not a socket"));
  70. w32_errors.Add(10040,
  71. Locale.GetText("Message too long"));
  72. w32_errors.Add(10043,
  73. Locale.GetText("proto no supported"));
  74. w32_errors.Add(10044,
  75. Locale.GetText("socket not supproted"));
  76. w32_errors.Add(10045,
  77. Locale.GetText("Operation not supported"));
  78. w32_errors.Add(10047,
  79. Locale.GetText("AF not supported"));
  80. w32_errors.Add(10048,
  81. Locale.GetText("Address already in use"));
  82. w32_errors.Add(10050,
  83. Locale.GetText("Network subsystem is down"));
  84. w32_errors.Add(10051,
  85. Locale.GetText("Network is unreachable"));
  86. w32_errors.Add(10054,
  87. Locale.GetText("Connection reset by peer"));
  88. w32_errors.Add(10055,
  89. Locale.GetText("Not enough buffer space is available"));
  90. w32_errors.Add(10056,
  91. Locale.GetText("Socket is already connected"));
  92. w32_errors.Add(10057,
  93. Locale.GetText("The socket is not connected"));
  94. w32_errors.Add(10058,
  95. Locale.GetText("The socket has been shut down"));
  96. w32_errors.Add(10060,
  97. Locale.GetText("Connection timed out"));
  98. w32_errors.Add(10061,
  99. Locale.GetText("Connection refused"));
  100. w32_errors.Add(10065,
  101. Locale.GetText("No route to host"));
  102. w32_errors.Add(10093,
  103. Locale.GetText("Winsock not initialized"));
  104. w32_errors.Add(10107,
  105. Locale.GetText("System call failed"));
  106. w32_errors.Add(11001,
  107. Locale.GetText("No such host is known"));
  108. w32_errors.Add(11002,
  109. Locale.GetText("A temporary error occurred on an authoritative name server. Try again later."));
  110. }
  111. private static string W32ErrorMessage(int error_code) {
  112. string message=(string)w32_errors[error_code];
  113. if(message==null) {
  114. return(Locale.GetText("Some sort of w32 error occurred: ") + error_code.ToString());
  115. } else {
  116. return(message);
  117. }
  118. }
  119. }
  120. }