ArgumentNullException.cs 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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. [System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
  19. public class ArgumentNullException : ArgumentException
  20. {
  21. // Creates a new ArgumentNullException with its message
  22. // string set to a default message explaining an argument was null.
  23. public ArgumentNullException()
  24. : base(SR.ArgumentNull_Generic)
  25. {
  26. // Use E_POINTER - COM used that for null pointers. Description is "invalid pointer"
  27. HResult = HResults.E_POINTER;
  28. }
  29. public ArgumentNullException(string paramName)
  30. : base(SR.ArgumentNull_Generic, paramName)
  31. {
  32. HResult = HResults.E_POINTER;
  33. }
  34. public ArgumentNullException(string message, Exception innerException)
  35. : base(message, innerException)
  36. {
  37. HResult = HResults.E_POINTER;
  38. }
  39. public ArgumentNullException(string paramName, string message)
  40. : base(message, paramName)
  41. {
  42. HResult = HResults.E_POINTER;
  43. }
  44. protected ArgumentNullException(SerializationInfo info, StreamingContext context) : base(info, context)
  45. {
  46. }
  47. }
  48. }