InsufficientMemoryException.cs 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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. using System.Runtime.Serialization;
  5. namespace System
  6. {
  7. /// <summary>
  8. /// Purpose: The exception class for running out of memory
  9. /// but most likely in a non-fatal way that shouldn't
  10. /// be affected by escalation policy. Use this for cases
  11. /// like MemoryFailPoint or a TryAllocate method, where you
  12. /// expect OOM's with no shared state corruption and you
  13. /// want to recover from these errors.
  14. /// </summary>
  15. [Serializable]
  16. [System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
  17. public sealed class InsufficientMemoryException : OutOfMemoryException
  18. {
  19. public InsufficientMemoryException() : base(
  20. #if CORECLR
  21. GetMessageFromNativeResources(ExceptionMessageKind.OutOfMemory)
  22. #else
  23. SR.Arg_OutOfMemoryException
  24. #endif
  25. )
  26. {
  27. HResult = HResults.COR_E_INSUFFICIENTMEMORY;
  28. }
  29. public InsufficientMemoryException(string? message)
  30. : base(message)
  31. {
  32. HResult = HResults.COR_E_INSUFFICIENTMEMORY;
  33. }
  34. public InsufficientMemoryException(string? message, Exception? innerException)
  35. : base(message, innerException)
  36. {
  37. HResult = HResults.COR_E_INSUFFICIENTMEMORY;
  38. }
  39. private InsufficientMemoryException(SerializationInfo info, StreamingContext context) : base(info, context)
  40. {
  41. }
  42. }
  43. }