ArgumentNullException.cs 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. // Licensed to the .NET Foundation under one or more agreements.
  2. // The .NET Foundation licenses this file to you under the MIT license.
  3. // See the LICENSE file in the project root for more information.
  4. /*=============================================================================
  5. **
  6. **
  7. **
  8. ** Purpose: Exception class for null arguments to a method.
  9. **
  10. **
  11. =============================================================================*/
  12. using System.Runtime.Serialization;
  13. namespace System
  14. {
  15. // The ArgumentException is thrown when an argument
  16. // is null when it shouldn't be.
  17. [Serializable]
  18. public class ArgumentNullException : ArgumentException
  19. {
  20. // Creates a new ArgumentNullException with its message
  21. // string set to a default message explaining an argument was null.
  22. public ArgumentNullException()
  23. : base(nameof(ArgumentNullException))
  24. {
  25. // Use E_POINTER - COM used that for null pointers. Description is "invalid pointer"
  26. HResult = HResults.E_POINTER;
  27. }
  28. public ArgumentNullException(string paramName)
  29. : base(paramName)
  30. {
  31. HResult = HResults.E_POINTER;
  32. }
  33. public ArgumentNullException(string message, Exception innerException)
  34. : base(message, innerException)
  35. {
  36. HResult = HResults.E_POINTER;
  37. }
  38. public ArgumentNullException(string paramName, string message)
  39. : base(message, paramName)
  40. {
  41. HResult = HResults.E_POINTER;
  42. }
  43. }
  44. }