コード例 #1
0
        private static Exception HandleKnownWin32Exception(Exception inner)
        {
            // These do not have .ctor with innerException, so we must always create wrapper to preserve stack trace.
            SocketException             asSocketException;
            HttpListenerException       asHttpListenerException;
            NetworkInformationException asNetworkInformationException;
            Win32Exception asWin32Exception;

            if ((asSocketException = inner as SocketException) != null)
            {
                var result = new WrapperSocketException(asSocketException);
                SetMatroshika(inner);
                return(result);
            }

            if ((asHttpListenerException = inner as HttpListenerException) != null)
            {
                var result = new WrapperHttpListenerException(asHttpListenerException);
                SetMatroshika(inner);
                return(result);
            }

            if ((asNetworkInformationException = inner as NetworkInformationException) != null)
            {
                var result = new WrapperNetworkInformationException(asNetworkInformationException);
                SetMatroshika(inner);
                return(result);
            }

            if ((asWin32Exception = inner as Win32Exception) != null)
            {
                if (_safeCreateWrapperWin32ExceptionMethod.IsSecuritySafeCritical)
                {
                    var result = SafeCreateWrapperWin32Exception(asWin32Exception);
                    return(result);
                }
                else
                {
                    return(new TargetInvocationException(asWin32Exception.Message, asWin32Exception));
                }
            }

            return(null);
        }
コード例 #2
0
        static Exception HandleKnownWin32Exception(Exception inner)
        {
            if (inner is SocketException asSocketException)
            {
                var result = new WrapperSocketException(asSocketException);
                SetMatroshika(inner);
                return(result);
            }

            if (inner is HttpListenerException asHttpListenerException)
            {
                var result = new WrapperHttpListenerException(asHttpListenerException);
                SetMatroshika(inner);
                return(result);
            }

            if (inner is NetworkInformationException asNetworkInformationException)
            {
                var result = new WrapperNetworkInformationException(asNetworkInformationException);
                SetMatroshika(inner);
                return(result);
            }

            if (inner is Win32Exception asWin32Exception)
            {
                if (safeCreateWrapperWin32ExceptionMethod.IsSecuritySafeCritical)
                {
                    var result = SafeCreateWrapperWin32Exception(asWin32Exception);
                    return(result);
                }
                else
                {
                    return(new TargetInvocationException(asWin32Exception.Message, asWin32Exception));
                }
            }

            return(null);
        }
コード例 #3
0
ファイル: ExceptionDispatchInfo.cs プロジェクト: Indifer/Test
		private static Exception HandleKnownWin32Exception( Exception inner )
		{
			// These do not have .ctor with innerException, so we must always create wrapper to preserve stack trace.
			SocketException asSocketException;
			HttpListenerException asHttpListenerException;
			NetworkInformationException asNetworkInformationException;
			Win32Exception asWin32Exception;

			if ( ( asSocketException = inner as SocketException ) != null )
			{
				var result = new WrapperSocketException( asSocketException );
				SetMatroshika( inner );
				return result;
			}

			if ( ( asHttpListenerException = inner as HttpListenerException ) != null )
			{
				var result = new WrapperHttpListenerException( asHttpListenerException );
				SetMatroshika( inner );
				return result;
			}

			if ( ( asNetworkInformationException = inner as NetworkInformationException ) != null )
			{
				var result = new WrapperNetworkInformationException( asNetworkInformationException );
				SetMatroshika( inner );
				return result;
			}

			if ( ( asWin32Exception = inner as Win32Exception ) != null )
			{
				if ( _safeCreateWrapperWin32ExceptionMethod.IsSecuritySafeCritical )
				{
					var result = SafeCreateWrapperWin32Exception( asWin32Exception );
					return result;
				}
				else
				{
					return new TargetInvocationException( asWin32Exception.Message, asWin32Exception );
				}
			}

			return null;
		}