Last active
October 29, 2021 00:25
-
-
Save djeikyb/48ec0b7362b1676c01c2ab50b6d9d560 to your computer and use it in GitHub Desktop.
An exception to throw in the default branch of a switch..case that ought to be exhaustive
This file contains hidden or 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
using System; | |
namespace Example | |
{ | |
/// <summary> | |
/// </summary> | |
/// <typeparam name="T">Must be an enum type</typeparam> | |
/// <remarks> | |
/// Follows the pattern of <see cref="SwitchExpressionException"/> | |
/// </remarks> | |
public class EnumSwitchException<T> : InvalidOperationException | |
where T : Enum | |
{ | |
public EnumSwitchException(T actualValue) | |
: base( | |
$"Some values of the enum {typeof(T)} are not processed inside switch: {actualValue}" | |
) | |
{ | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Use like: