Esempio n. 1
0
        static ExceptionInfo GetExceptionInfo(Exception ex, string userMessage)
        {
            var info = new ExceptionInfo();
            try
            {
                info.Message = userMessage;

                string fullErrorMessage = string.Empty;
                Exception innermost = GetInnerMostException(ex, out fullErrorMessage);
                if (innermost != null)
                {
                    info.Exception = innermost;
                    info.ExceptionName = fullErrorMessage;
                    info.Source = innermost.Source;
                    info.StackTrace = innermost.StackTrace;
                    if (innermost.TargetSite != null)
                        info.Target = innermost.TargetSite.ToString();
                    if (innermost != null && innermost != ex)
                        info.StackTrace += "\r\n...\r\n" + ex.StackTrace;
                }
            }
            catch
            {
            }
            return info;
        }
Esempio n. 2
0
        static string GetFormattedExceptionText(ExceptionInfo e, bool pad)
        {
            string sql = string.Empty;
            string crlf = Environment.NewLine;
            string ret = "";

            if (e == null)
            {
                ret = PadTitle("Error") + "No exception details are available" + crlf;
            }
            else
            {
                ret =
                    PadTitle("Error") + e.Message + crlf +
                    PadTitle("Exception") + e.ExceptionName + crlf +
                    PadTitle("Source") + e.Source + crlf +
                    PadTitle("Target") + e.Target + crlf +
                    sql +
                    PadTitle("StackTrace") + PadLeftMargin(e.StackTrace, pad);
            }

            return ret;
        }