Esempio n. 1
0
        internal static Exception Map(uv_err_code error, string name = null)
        {
            if (error == uv_err_code.UV_OK)
            {
                return(null);
            }

            switch (error)
            {
            case uv_err_code.UV_EINVAL:
                return(new ArgumentException(UVException.StringError(error)));

            case uv_err_code.UV_ENOENT:
                var path = (name == null ? System.IO.Directory.GetCurrentDirectory() : Path.Combine(System.IO.Directory.GetCurrentDirectory(), name));
                return(new System.IO.FileNotFoundException(string.Format("Could not find file '{0}'.", path), path));

            case uv_err_code.UV_EADDRINUSE:
                return(new SocketException(10048));

            case uv_err_code.UV_EADDRNOTAVAIL:
                return(new SocketException(10049));

            case uv_err_code.UV_ECONNREFUSED:
                return(new SocketException(10061));

            case uv_err_code.UV_ENOTSUP:
                return(new NotSupportedException());

            default:
                return(new UVException(error));
            }
        }
Esempio n. 2
0
        internal static Exception Map(int systemErrorCode, string name = null)
        {
            // no error, just return null
            if (!(systemErrorCode < 0))
            {
                return(null);
            }

            // map some error codes
            var errorCode = UVException.Map(systemErrorCode);

            switch (errorCode)
            {
            case UVErrorCode.EINVAL:
                return(new ArgumentException(UVException.StringError(systemErrorCode)));

            case UVErrorCode.ENOENT:
                var path = (name == null ? System.IO.Directory.GetCurrentDirectory() : Path.Combine(System.IO.Directory.GetCurrentDirectory(), name));
                return(new System.IO.FileNotFoundException(string.Format("Could not find file '{0}'.", path), path));

            case UVErrorCode.ENOTSUP:
                return(new NotSupportedException());

            default:
                break;
            }

            // everything else is a UVException
            return(new UVException(systemErrorCode));
        }