Win32Exception.cs 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. //
  2. // System.ComponentModel.Win32Exceptioncs
  3. //
  4. // Author:
  5. // Dick Porter ([email protected])
  6. //
  7. // (C) 2002 Ximian, Inc. http://www.ximian.com
  8. //
  9. using System.Runtime.InteropServices;
  10. using System.Runtime.Serialization;
  11. using System.Collections;
  12. using System.Globalization;
  13. namespace System.ComponentModel
  14. {
  15. [Serializable]
  16. public class Win32Exception : ExternalException
  17. {
  18. private int native_error_code;
  19. public Win32Exception ()
  20. : base (W32ErrorMessage(Marshal.GetLastWin32Error()),
  21. Marshal.GetLastWin32Error()) {
  22. native_error_code=Marshal.GetLastWin32Error();
  23. }
  24. public Win32Exception(int error)
  25. : base (W32ErrorMessage(error), error) {
  26. native_error_code=error;
  27. }
  28. public Win32Exception(int error, string message)
  29. : base (message, error) {
  30. native_error_code=error;
  31. }
  32. protected Win32Exception(SerializationInfo info,
  33. StreamingContext context)
  34. : base (info, context) {
  35. }
  36. public int NativeErrorCode {
  37. get {
  38. return(native_error_code);
  39. }
  40. }
  41. [MonoTODO]
  42. public override void GetObjectData(SerializationInfo info,
  43. StreamingContext context) {
  44. if(info==null) {
  45. throw new ArgumentNullException();
  46. }
  47. throw new NotImplementedException();
  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(11001,
  57. Locale.GetText("No such host is known"));
  58. w32_errors.Add(10047,
  59. Locale.GetText("AF not supported"));
  60. w32_errors.Add(10043,
  61. Locale.GetText("proto no supported"));
  62. w32_errors.Add(10044,
  63. Locale.GetText("socket not supproted"));
  64. w32_errors.Add(10004,
  65. Locale.GetText("interrupted"));
  66. w32_errors.Add(10013,
  67. Locale.GetText("Access denied"));
  68. w32_errors.Add(11002,
  69. Locale.GetText("A temporary error occurred on an authoritative name server. Try again later."));
  70. w32_errors.Add(10022,
  71. Locale.GetText("Invalid arguments"));
  72. w32_errors.Add(10050,
  73. Locale.GetText("Network subsystem is down"));
  74. w32_errors.Add(10051,
  75. Locale.GetText("Network is unreachable"));
  76. w32_errors.Add(10061,
  77. Locale.GetText("Connection refused"));
  78. w32_errors.Add(10045,
  79. Locale.GetText("Operation not supported"));
  80. w32_errors.Add(10038,
  81. Locale.GetText("The descriptor is not a socket"));
  82. w32_errors.Add(10055,
  83. Locale.GetText("Not enough buffer space is available"));
  84. w32_errors.Add(10056,
  85. Locale.GetText("Socket is already connected"));
  86. w32_errors.Add(10048,
  87. Locale.GetText("Address already in use"));
  88. w32_errors.Add(10057,
  89. Locale.GetText("The socket is not connected"));
  90. w32_errors.Add(10058,
  91. Locale.GetText("The socket has been shut down"));
  92. w32_errors.Add(10093,
  93. Locale.GetText("Winsock not initialized"));
  94. }
  95. private static string W32ErrorMessage(int error_code) {
  96. string message=(string)w32_errors[error_code];
  97. if(message==null) {
  98. return(Locale.GetText("Some sort of w32 error occurred"));
  99. } else {
  100. return(message);
  101. }
  102. }
  103. }
  104. }