| | 1 | | // Copyright (c) Microsoft Corporation. All rights reserved. |
| | 2 | | // Licensed under the MIT License. |
| | 3 | |
|
| | 4 | | using System; |
| | 5 | | using System.Threading; |
| | 6 | | using System.Threading.Tasks; |
| | 7 | |
|
| | 8 | | namespace Azure.Messaging.EventHubs.Core |
| | 9 | | { |
| | 10 | | /// <summary> |
| | 11 | | /// The set of extensions for the <see cref="Exception" /> |
| | 12 | | /// class. |
| | 13 | | /// </summary> |
| | 14 | | /// |
| | 15 | | internal static class ExceptionExtensions |
| | 16 | | { |
| | 17 | | /// <summary> |
| | 18 | | /// Serves as an inverse to the "is" operator, determining whether the <paramref name="instance"/> |
| | 19 | | /// is NOT of type <typeparamref name="T"/>. |
| | 20 | | /// </summary> |
| | 21 | | /// |
| | 22 | | /// <typeparam name="T">The <see cref="Exception" /> type to test the <paramref name="instance"/> against.</type |
| | 23 | | /// |
| | 24 | | /// <param name="instance">The instance to consider.</param> |
| | 25 | | /// |
| | 26 | | /// <returns><c>true</c> if the specified instance is NOT of type <typeparamref name="T"/>; otherwise, <c>false< |
| | 27 | | /// |
| 58 | 28 | | public static bool IsNotType<T>(this Exception instance) where T : Exception => (!(instance is T)); |
| | 29 | |
|
| | 30 | | /// <summary> |
| | 31 | | /// Determines whether the <paramref name="instance"/> is a well-known fatal exception and should avoid retrie |
| | 32 | | /// logging, and similar activities. |
| | 33 | | /// </summary> |
| | 34 | | /// |
| | 35 | | /// <param name="instance">The instance to consider.</param> |
| | 36 | | /// |
| | 37 | | /// <returns><c>true</c> if the specified instance should be considered fatal; otherwise, <c>false</c>.</returns |
| | 38 | | /// |
| | 39 | | public static bool IsFatalException(this Exception instance) => |
| 106 | 40 | | (instance is TaskCanceledException |
| 106 | 41 | | || instance is OutOfMemoryException |
| 106 | 42 | | || instance is StackOverflowException |
| 106 | 43 | | || instance is ThreadAbortException); |
| | 44 | | } |
| | 45 | | } |