Skip to content

Commit

Permalink
Add new System.Diagnostics.UnreachableException polyfill
Browse files Browse the repository at this point in the history
The System.Diagnostics.UnreachableException.cs file was not actually auto-generated (see Sergio0694#88).

Fixes Sergio0694#60
  • Loading branch information
0xced committed Nov 8, 2023
1 parent 2689b7e commit 1647e0a
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// <auto-generated/>
#pragma warning disable
#nullable enable annotations

// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

namespace System.Diagnostics
{
/// <summary>
/// Exception thrown when the program executes an instruction that was thought to be unreachable.
/// </summary>
public sealed class UnreachableException : Exception
{
/// <summary>
/// Initializes a new instance of the <see cref="UnreachableException"/> class with the default error message.
/// </summary>
public UnreachableException()
: base("The program executed an instruction that was thought to be unreachable.")
{
}

/// <summary>
/// Initializes a new instance of the <see cref="UnreachableException"/> class with a specified error message.
/// </summary>
/// <param name="message">The error message that explains the reason for the exception.</param>
public UnreachableException(string? message)
: base(message)
{
}

/// <summary>
/// Initializes a new instance of the <see cref="UnreachableException"/> class with a specified error message and a reference to the inner exception that is the cause of this exception.
/// </summary>
/// <param name="message">The error message that explains the reason for the exception.</param>
/// <param name="innerException">The exception that is the cause of the current exception.</param>
public UnreachableException(string? message, Exception? innerException)
: base(message, innerException)
{
}
}
}
9 changes: 9 additions & 0 deletions tests/PolySharp.Tests/LanguageFeatures.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using System;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.CompilerServices;
using System.Runtime.ExceptionServices;
using System.Runtime.Versioning;
#if !NETSTANDARD2_1
using System.Threading.Tasks;
Expand Down Expand Up @@ -36,6 +38,13 @@ public void Throws([DoesNotReturnIf(true)] bool value)
{
}

// UnreachableException
public object Unreachable()
{
ExceptionDispatchInfo.Capture(new Exception()).Throw();
throw new UnreachableException();
}

// MaybeNullAttribute
[return: MaybeNull]
public string ModifyValue()
Expand Down

0 comments on commit 1647e0a

Please sign in to comment.