-
Notifications
You must be signed in to change notification settings - Fork 19
/
Exception.cs
27 lines (26 loc) · 1.04 KB
/
Exception.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
namespace SignInMaui.MSALClient
{
/// <summary>
/// Static class for a few extension methods related to Exception throwing and handling
/// </summary>
/// <typeparam name="TException">The type of the exception to throw/work with.</typeparam>
public static class Exception<TException> where TException : Exception, new()
{
/// <summary>
/// Throws and exception of the requested type, if the predicate is true
/// </summary>
/// <param name="predicate">The predicate to evaluate.</param>
/// <param name="message">The message to pass to the raised exception.</param>
/// <autogeneratedoc />
public static void ThrowOn(Func<bool> predicate, string message = null)
{
if (predicate())
{
TException toThrow = Activator.CreateInstance(typeof(TException), message) as TException;
throw toThrow;
}
}
}
}