WbemException.cs 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. //------------------------------------------------------------
  2. // Copyright (c) Microsoft Corporation. All rights reserved.
  3. //------------------------------------------------------------
  4. namespace System.ServiceModel.Administration
  5. {
  6. using System;
  7. using System.ComponentModel;
  8. using System.Diagnostics;
  9. internal class WbemException : Win32Exception
  10. {
  11. internal WbemException(WbemNative.WbemStatus hr)
  12. : base((int)hr)
  13. {
  14. }
  15. internal WbemException(int hr)
  16. : base(hr)
  17. {
  18. }
  19. internal WbemException(int hr, string message)
  20. : base(hr, message)
  21. {
  22. }
  23. internal static void Throw(WbemNative.WbemStatus hr)
  24. {
  25. switch (hr)
  26. {
  27. case WbemNative.WbemStatus.WBEM_E_NOT_FOUND:
  28. throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new WbemInstanceNotFoundException());
  29. case WbemNative.WbemStatus.WBEM_E_INVALID_PARAMETER:
  30. throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new WbemInvalidParameterException());
  31. case WbemNative.WbemStatus.WBEM_E_NOT_SUPPORTED:
  32. throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new WbemNotSupportedException());
  33. case WbemNative.WbemStatus.WBEM_E_INVALID_METHOD:
  34. throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new WbemInvalidMethodException());
  35. default:
  36. throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new WbemException(hr));
  37. }
  38. }
  39. internal static void ThrowIfFail(int hr)
  40. {
  41. if (hr < 0)
  42. {
  43. Throw((WbemNative.WbemStatus)hr);
  44. }
  45. }
  46. }
  47. internal class WbemInstanceNotFoundException : WbemException
  48. {
  49. internal WbemInstanceNotFoundException()
  50. : base(WbemNative.WbemStatus.WBEM_E_NOT_FOUND)
  51. {
  52. }
  53. }
  54. internal class WbemInvalidParameterException : WbemException
  55. {
  56. internal WbemInvalidParameterException(string name)
  57. : base((int)WbemNative.WbemStatus.WBEM_E_INVALID_PARAMETER, name)
  58. {
  59. }
  60. internal WbemInvalidParameterException()
  61. : base(WbemNative.WbemStatus.WBEM_E_INVALID_PARAMETER)
  62. {
  63. }
  64. }
  65. internal class WbemNotSupportedException : WbemException
  66. {
  67. internal WbemNotSupportedException()
  68. : base(WbemNative.WbemStatus.WBEM_E_NOT_SUPPORTED)
  69. {
  70. }
  71. }
  72. internal class WbemInvalidMethodException : WbemException
  73. {
  74. internal WbemInvalidMethodException()
  75. : base(WbemNative.WbemStatus.WBEM_E_INVALID_METHOD)
  76. {
  77. }
  78. }
  79. }