< Summary

Class:Azure.Messaging.ServiceBus.ServiceBusException
Assembly:Azure.Messaging.ServiceBus
File(s):C:\Git\azure-sdk-for-net\sdk\servicebus\Azure.Messaging.ServiceBus\src\Primitives\ServiceBusException.cs
Covered lines:19
Uncovered lines:8
Coverable lines:27
Total lines:128
Line coverage:70.3% (19 of 27)
Covered branches:3
Total branches:4
Branch coverage:75% (3 of 4)

Metrics

MethodCyclomatic complexity Line coverage Branch coverage
get_IsTransient()-100%100%
get_Reason()-100%100%
get_EntityPath()-100%100%
get_ProcessorErrorSource()-0%100%
get_Message()-50%50%
.ctor(...)-100%100%
.ctor(...)-100%100%
.ctor()-0%100%

File(s)

C:\Git\azure-sdk-for-net\sdk\servicebus\Azure.Messaging.ServiceBus\src\Primitives\ServiceBusException.cs

#LineLine coverage
 1// Copyright (c) Microsoft Corporation. All rights reserved.
 2// Licensed under the MIT License.
 3
 4using System;
 5using System.Globalization;
 6
 7namespace Azure.Messaging.ServiceBus
 8{
 9    /// <summary>
 10    ///   Serves as a basis for exceptions produced within the Service Bus
 11    ///   context.
 12    /// </summary>
 13    ///
 14    /// <seealso cref="System.Exception" />
 15    ///
 16    public class ServiceBusException : Exception
 17    {
 18        /// <summary>
 19        ///   Indicates whether an exception should be considered transient or final.
 20        /// </summary>
 21        ///
 22        /// <value><c>true</c> if the exception is likely transient; otherwise, <c>false</c>.</value>
 23        ///
 3024        public bool IsTransient { get; }
 25
 26        /// <summary>
 27        ///   The reason for the failure of an Service Bus operation that resulted
 28        ///   in the exception.
 29        /// </summary>
 30        ///
 20431        public ServiceBusFailureReason Reason { get; }
 32
 33        /// <summary>
 34        ///   The name of the Service Bus to which the exception is associated.
 35        /// </summary>
 36        ///
 37        /// <value>The name of the Service Bus entity, if available; otherwise, <c>null</c>.</value>
 38        ///
 8839        public string EntityPath { get; }
 40
 41        /// <summary>
 42        /// Can be used to hold the processor error source when we rethrow exceptions.
 43        /// </summary>
 044        internal ServiceBusErrorSource? ProcessorErrorSource { get; set; }
 45
 46        /// <summary>
 47        ///   Gets a message that describes the current exception.
 48        /// </summary>
 49        ///
 50        public override string Message
 51        {
 52            get
 53            {
 8854                if (string.IsNullOrEmpty(EntityPath))
 55                {
 8856                    return string.Format(
 8857                        CultureInfo.InvariantCulture,
 8858                        "{0} ({1})",
 8859                        base.Message,
 8860                        Reason);
 61                }
 062                return string.Format(
 063                    CultureInfo.InvariantCulture,
 064                    "{0} ({1} - {2})",
 065                    base.Message,
 066                    EntityPath,
 067                    Reason);
 68            }
 69        }
 70
 71        /// <summary>
 72        ///   Initializes a new instance of the <see cref="ServiceBusException"/> class, using the <paramref name="reaso
 73        ///   to detect whether or not it should be transient.
 74        /// </summary>
 75        ///
 76        /// <param name="message">The error message that explains the reason for the exception.</param>
 77        /// <param name="reason">The reason for the failure that resulted in the exception.</param>
 78        /// <param name="entityPath">The name of the Service Bus entity to which the exception is associated.</param>
 79        /// <param name="innerException"></param>
 80        ///
 81        public ServiceBusException(
 82            string message,
 83            ServiceBusFailureReason reason,
 84            string entityPath = default,
 85            Exception innerException = default) :
 11286            this(default, message, entityPath, reason, innerException)
 87        {
 88            switch (reason)
 89            {
 90                case ServiceBusFailureReason.ServiceCommunicationProblem:
 91                case ServiceBusFailureReason.ServiceTimeout:
 92                case ServiceBusFailureReason.ServiceBusy:
 1693                    IsTransient = true;
 1694                    break;
 95
 96                default:
 9697                    IsTransient = false;
 98                    break;
 99            }
 96100        }
 101
 102        /// <summary>
 103        ///   Initializes a new instance of the <see cref="ServiceBusException"/> class.
 104        /// </summary>
 105        ///
 106        /// <param name="isTransient"><c>true</c> if the exception should be considered transient; otherwise, <c>false</
 107        /// <param name="message">The error message that explains the reason for the exception.</param>
 108        /// <param name="entityName">The name of the Service Bus entity to which the exception is associated.</param>
 109        /// <param name="reason">The reason for the failure that resulted in the exception.</param>
 110        /// <param name="innerException">The exception that is the cause of the current exception, or a null reference i
 111        ///
 112        public ServiceBusException(bool isTransient,
 113                                  string message,
 114                                  string entityName = default,
 115                                  ServiceBusFailureReason reason = ServiceBusFailureReason.GeneralError,
 122116                                  Exception innerException = default) : base(message, innerException)
 117        {
 122118            IsTransient = isTransient;
 122119            EntityPath = entityName;
 122120            Reason = reason;
 122121        }
 122
 123        /// <summary>
 124        ///
 125        /// </summary>
 0126        public ServiceBusException() { }
 127    }
 128}