-
-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add
UnreachableException
, which was introduced in .NET 7 (#78)
* Add `UnreachableException`, which was introduced in .NET 7 * Added test to check targetframework compatiblity
- Loading branch information
Showing
2 changed files
with
68 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
// <auto-generated /> | ||
|
||
#if !NET7_0_OR_GREATER | ||
|
||
#nullable enable | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Diagnostics.CodeAnalysis; | ||
using System.Text; | ||
|
||
namespace System.Diagnostics; | ||
|
||
/// <summary> | ||
/// Exception thrown when the program executes an instruction that was thought to be unreachable. | ||
/// </summary> | ||
/// <seealso href="https://learn.microsoft.com/en-us/dotnet/api/system.diagnostics.unreachableexception"/> | ||
/// <seealso href="https://source.dot.net/#System.Private.CoreLib/src/libraries/System.Private.CoreLib/src/System/Diagnostics/UnreachableException.cs"/> | ||
[ExcludeFromCodeCoverage] | ||
[DebuggerNonUserCode] | ||
#if PolyPublic | ||
public | ||
#endif | ||
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) | ||
{ | ||
} | ||
} | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
namespace Tests; | ||
|
||
[TestFixture] | ||
public class UnreachableExceptionTests | ||
{ | ||
[Test] | ||
public void UnreachableException_Compatiblity_with_all_TargetFrameworks() | ||
{ | ||
_ = Assert.Throws<UnreachableException>(() => throw new UnreachableException()); | ||
} | ||
} |