Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mark exception throwing helpers as DoesNotReturn. #1354

Merged
merged 1 commit into from
Oct 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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