protected COMSurvivableException(string messageWithAnyStateData, Reviver reviver) : base(messageWithAnyStateData)
        {
            if (string.IsNullOrWhiteSpace(messageWithAnyStateData))
            {
                throw new ArgumentException("Null/blank messageWithAnyStateData specified");
            }
            if (reviver == null)
            {
                throw new ArgumentNullException("reviver");
            }

            lock (_revivers)
            {
                _revivers[UniqueErrorCode] = reviver;
            }
            HResult = CustomErrorHResultGenerator.GetHResult(UniqueErrorCode);
        }
        [DebuggerStepThrough]         // No benefit to the debugger breaking here, if an exception is raised then we want the debugger to stop where the translated exception is caught
        public static void RethrowAsOriginalIfPossible(COMException e)
        {
            if (e == null)
            {
                throw new ArgumentNullException("e");
            }

            var     uniqueErrorCode = CustomErrorHResultGenerator.GetErrorCode(e.HResult);
            Reviver reviver;

            lock (_revivers)
            {
                if (!_revivers.TryGetValue(uniqueErrorCode, out reviver))
                {
                    return;
                }
            }
            var revivedException = reviver(e.Message);

            if (revivedException != null)
            {
                throw revivedException;
            }
        }
 public static bool IsComSurvivableHResult(int hresult)
 {
     return(CustomErrorHResultGenerator.IsComSurvivableHResult(hresult));
 }