Skip to content
This repository has been archived by the owner on Nov 1, 2020. It is now read-only.

Commit

Permalink
Move InsufficientMemory, OutOfMemory and ThreadInterrupted exceptions…
Browse files Browse the repository at this point in the history
… (#18049)

* Move following exceptions to shared:

    - InsufficientMemory,
    - OutOfMemory
    - ThreadInterrupted

Related to: dotnet/coreclr#17904

Reduced diff in RegistryKey visible between coreclr and corert

Signed-off-by: dotnet-bot <dotnet-bot@microsoft.com>
  • Loading branch information
maryamariyan authored and jkotas committed May 22, 2018
1 parent 58afa17 commit 872d9af
Show file tree
Hide file tree
Showing 4 changed files with 138 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@
<Compile Include="$(MSBuildThisFileDirectory)System\IFormattable.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\IndexOutOfRangeException.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\InsufficientExecutionStackException.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\InsufficientMemoryException.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\InvalidCastException.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\InvalidOperationException.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\InvalidProgramException.cs" />
Expand Down Expand Up @@ -273,6 +274,7 @@
<Compile Include="$(MSBuildThisFileDirectory)System\ObjectDisposedException.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\ObsoleteAttribute.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\OperationCanceledException.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\OutOfMemoryException.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\OverflowException.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\ParamArrayAttribute.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\ParamsArray.cs" />
Expand Down Expand Up @@ -572,6 +574,7 @@
<Compile Include="$(MSBuildThisFileDirectory)System\Threading\Tasks\ValueTask.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Threading\Tasks\Sources\IValueTaskSource.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Threading\ThreadAbortException.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Threading\ThreadInterruptedException.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Threading\ThreadPriority.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Threading\ThreadStart.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Threading\ThreadStartException.cs" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System;
using System.Runtime.Serialization;

namespace System
{
/// <summary>
/// Purpose: The exception class for running out of memory
/// but most likely in a non-fatal way that shouldn't
/// be affected by escalation policy. Use this for cases
/// like MemoryFailPoint or a TryAllocate method, where you
/// expect OOM's with no shared state corruption and you
/// want to recover from these errors.
/// </summary>
[Serializable]
[System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
public sealed class InsufficientMemoryException : OutOfMemoryException
{
public InsufficientMemoryException() : base(
#if CORECLR
GetMessageFromNativeResources(ExceptionMessageKind.OutOfMemory)
#else
SR.Arg_OutOfMemoryException
#endif
)
{
HResult = HResults.COR_E_INSUFFICIENTMEMORY;
}

public InsufficientMemoryException(String message)
: base(message)
{
HResult = HResults.COR_E_INSUFFICIENTMEMORY;
}

public InsufficientMemoryException(String message, Exception innerException)
: base(message, innerException)
{
HResult = HResults.COR_E_INSUFFICIENTMEMORY;
}

private InsufficientMemoryException(SerializationInfo info, StreamingContext context) : base(info, context)
{
}
}
}
43 changes: 43 additions & 0 deletions src/System.Private.CoreLib/shared/System/OutOfMemoryException.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System.Runtime.Serialization;

namespace System
{
/// <summary>
/// The exception class for OOM.
/// </summary>
[Serializable]
[System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
public class OutOfMemoryException : SystemException
{
public OutOfMemoryException() : base(
#if CORECLR
GetMessageFromNativeResources(ExceptionMessageKind.OutOfMemory)
#else
SR.Arg_OutOfMemoryException
#endif
)
{
HResult = HResults.COR_E_OUTOFMEMORY;
}

public OutOfMemoryException(String message)
: base(message)
{
HResult = HResults.COR_E_OUTOFMEMORY;
}

public OutOfMemoryException(String message, Exception innerException)
: base(message, innerException)
{
HResult = HResults.COR_E_OUTOFMEMORY;
}

protected OutOfMemoryException(SerializationInfo info, StreamingContext context) : base(info, context)
{
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System.Runtime.Serialization;

namespace System.Threading
{
/// <summary>
/// An exception class to indicate that the thread was interrupted from a waiting state.
/// </summary>
[Serializable]
[System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
public class ThreadInterruptedException : SystemException
{
public ThreadInterruptedException() : base(
#if CORECLR
GetMessageFromNativeResources(ExceptionMessageKind.ThreadInterrupted)
#else
SR.Threading_ThreadInterrupted
#endif
)
{
HResult = HResults.COR_E_THREADINTERRUPTED;
}

public ThreadInterruptedException(String message)
: base(message)
{
HResult = HResults.COR_E_THREADINTERRUPTED;
}

public ThreadInterruptedException(String message, Exception innerException)
: base(message, innerException)
{
HResult = HResults.COR_E_THREADINTERRUPTED;
}

protected ThreadInterruptedException(SerializationInfo info, StreamingContext context) : base(info, context)
{
}
}
}

0 comments on commit 872d9af

Please sign in to comment.