Exemplo n.º 1
0
        /// <summary>
        /// Decode an exception from an input stream </summary>
        /// <param name="input"> Data input </param>
        /// <returns> Decoded exception </returns>
        /// <exception cref="IOException"> On IO error </exception>
        //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
        //ORIGINAL LINE: public static FriendlyException decodeException(DataInput input) throws IOException
        public static FriendlyException decodeException(DataInput input)
        {
            DecodedException cause = null;

            while (input.readBoolean())
            {
                cause            = new DecodedException(input.readUTF(), input.readBoolean() ? input.readUTF() : null, cause);
                cause.StackTrace = decodeStackTrace(input);
            }

            FriendlyException exception = new FriendlyException(input.readUTF(), typeof(Severity).EnumConstants[input.readInt()], cause);

            exception.StackTrace = decodeStackTrace(input);
            return(exception);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Encode an exception to an output stream </summary>
        /// <param name="output"> Data output </param>
        /// <param name="exception"> Exception to encode </param>
        /// <exception cref="IOException"> On IO error </exception>
        //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
        //ORIGINAL LINE: public static void encodeException(DataOutput output, FriendlyException exception) throws IOException
        public static void encodeException(DataOutput output, FriendlyException exception)
        {
            IList <System.Exception> causes = new List <System.Exception>();

            System.Exception next = exception.InnerException;

            while (next != null)
            {
                causes.Add(next);
                next = next.InnerException;
            }

            for (int i = causes.Count - 1; i >= 0; i--)
            {
                System.Exception cause = causes[i];
                output.writeBoolean(true);

                string message;

                if (cause is DecodedException)
                {
                    output.writeUTF(((DecodedException)cause).className);
                    message = ((DecodedException)cause).originalMessage;
                }
                else
                {
                    //JAVA TO C# CONVERTER WARNING: The .NET Type.FullName property will not always yield results identical to the Java Class.getName method:
                    output.writeUTF(cause.GetType().FullName);
                    message = cause.Message;
                }

                output.writeBoolean(!string.ReferenceEquals(message, null));
                if (!string.ReferenceEquals(message, null))
                {
                    output.writeUTF(message);
                }

                encodeStackTrace(output, cause);
            }

            output.writeBoolean(false);
            output.writeUTF(exception.Message);
            output.writeInt((int)exception.severity);


            encodeStackTrace(output, exception);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Log a FriendlyException appropriately according to its severity. </summary>
        /// <param name="log"> Logger instance to log it to </param>
        /// <param name="exception"> The exception itself </param>
        /// <param name="context"> An object that is included in the log </param>

        public static void log(Microsoft.Extensions.Logging.ILogger log, FriendlyException exception, object context)
        {
            switch (exception.severity)
            {
            case Severity.COMMON:
                log.LogDebug("Common failure for {}: {}", context, exception.Message);
                break;

            case Severity.SUSPICIOUS:
                log.LogWarning("Suspicious exception for {}", context, exception);
                break;

            case Severity.FAULT:
            default:
                log.LogError("Error in {}", context, exception);
                break;
            }
        }