Win32Exception.cs 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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. }
  65. private static string W32ErrorMessage(int error_code) {
  66. string message=(string)w32_errors[error_code];
  67. if(message==null) {
  68. return(Locale.GetText("Some sort of w32 error occurred"));
  69. } else {
  70. return(message);
  71. }
  72. }
  73. }
  74. }