Ejemplo n.º 1
0
        public static string FormatException(Exception x)
        {
            //
            //    Make sure rethrow exceptions are handled.
            //

            if (RethrowException.IsValidRethrowException(x))
            {
                x = x.UnwrapRethrown();
            }

            var message = $"@PX {x.GetType().Name}: {x.GetFullMessage()}";

            string info = null;

            if (_exceptionInfo.ContainsKey(x))
            {
                info = _exceptionInfo[x];
                _exceptionInfo.Remove(x);
            }

            if (!String.IsNullOrEmpty(info))
            {
                message += $" [{info}]";
            }

            string stackInfo;

            try
            {
                stackInfo = string.Join(Environment.NewLine + " <--- ", GetRelevantStack(x));
            }
            catch    //    handled
            {
                stackInfo = "{unknown}";
            }

            message += " - " + stackInfo;

            return(message);
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Возвращает повторно-выброшенное исключение содержащееся в rethrow-исключении.
 /// </summary>
 /// <param name="x">Объект исключения.</param>
 /// <returns></returns>
 public static Exception UnwrapRethrown(this Exception x)
 {
     return(RethrowException.IsValidRethrowException(x) ? x.InnerException : x);
 }