Skip to content

Commit

Permalink
Merge pull request #1354 from dotnet/dev/bartde/doesnotreturn
Browse files Browse the repository at this point in the history
Mark exception throwing helpers as DoesNotReturn.
  • Loading branch information
bartdesmet authored Oct 2, 2020
2 parents 28000ff + e3b05e6 commit 88efad6
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// 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.Diagnostics.CodeAnalysis;
using System.Runtime.ExceptionServices;

namespace System.Reactive.PlatformServices
Expand All @@ -13,6 +14,9 @@ namespace System.Reactive.PlatformServices
//
internal class DefaultExceptionServices/*Impl*/ : IExceptionServices
{
#pragma warning disable CS8763 // NB: On down-level platforms, Throw is not marked as DoesNotReturn.
[DoesNotReturn]
public void Rethrow(Exception exception) => ExceptionDispatchInfo.Capture(exception).Throw();
#pragma warning restore CS8763
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// See the LICENSE file in the project root for more information.

using System.ComponentModel;
using System.Diagnostics.CodeAnalysis;
using System.Reactive.PlatformServices;

namespace System.Reactive
Expand All @@ -11,6 +12,7 @@ internal static class ExceptionHelpers
{
private static readonly Lazy<IExceptionServices> Services = new Lazy<IExceptionServices>(Initialize);

[DoesNotReturn]
public static void Throw(this Exception exception) => Services.Value.Rethrow(exception);

public static void ThrowIfNotNull(this Exception? exception)
Expand Down Expand Up @@ -46,6 +48,7 @@ public interface IExceptionServices
/// Rethrows the specified exception.
/// </summary>
/// <param name="exception">Exception to rethrow.</param>
[DoesNotReturn]
void Rethrow(Exception exception);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// 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.Diagnostics.CodeAnalysis;
using System.Runtime.ExceptionServices;

namespace System.Reactive.PlatformServices
Expand All @@ -13,6 +14,9 @@ namespace System.Reactive.PlatformServices
//
internal class /*Default*/ExceptionServicesImpl : IExceptionServices
{
#pragma warning disable CS8763 // NB: On down-level platforms, Throw is not marked as DoesNotReturn.
[DoesNotReturn]
public void Rethrow(Exception exception) => ExceptionDispatchInfo.Capture(exception).Throw();
#pragma warning restore CS8763
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2408,6 +2408,7 @@ public HostSuspendingEventArgs() { }
}
public interface IExceptionServices
{
[System.Diagnostics.CodeAnalysis.DoesNotReturn]
void Rethrow(System.Exception exception);
}
public interface IHostLifecycleNotifications
Expand Down

0 comments on commit 88efad6

Please sign in to comment.