当前位置: 首页>>代码示例>>C#>>正文


C# Exception.GetBaseException方法代码示例

本文整理汇总了C#中Exception.GetBaseException方法的典型用法代码示例。如果您正苦于以下问题:C# Exception.GetBaseException方法的具体用法?C# Exception.GetBaseException怎么用?C# Exception.GetBaseException使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Exception的用法示例。


在下文中一共展示了Exception.GetBaseException方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: PosTest1

    public bool PosTest1()
    {
        bool retVal = true;

        TestLibrary.TestFramework.BeginScenario("PosTest1: Call GetBaseException when InnerException property is null reference");

        try
        {
            Exception desired = new Exception();
            Exception actual = desired.GetBaseException();

            if (!desired.Equals(actual))
            {
                TestLibrary.TestFramework.LogError("001.1", "Calling GetBaseException when InnerException property is null reference does not return current exception instance");
                TestLibrary.TestFramework.LogInformation("WARNING [LOCAL VARIABLES] desired = " + desired + ", actual = " + actual);
                retVal = false;
            }
        }
        catch (Exception e)
        {
            TestLibrary.TestFramework.LogError("001.0", "Unexpected exception: " + e);
            TestLibrary.TestFramework.LogInformation(e.StackTrace);
            retVal = false;
        }

        return retVal;
    }
开发者ID:l1183479157,项目名称:coreclr,代码行数:27,代码来源:exceptiongetbaseexception.cs

示例2: HttpError

 /// <summary>
 /// Initializes a new instance of the <see cref="HttpError"/> class from a given <see cref="Exception"/> instance and
 /// <see cref="System.Web.HttpContext"/> instance representing the HTTP context during the exception.
 /// </summary>
 /// <param name="e">The e.</param>
 /// <param name="httpContext">The HTTP context.</param>
 public HttpError(Exception e, HttpContext httpContext)
 {
     if (e == null)
         throw new ArgumentNullException("e");
     Exception = e;
     // load the basic information.
     var baseException = e.GetBaseException();
     HostName = Environment.MachineName;
     TypeName = baseException.GetType().FullName;
     Message = baseException.Message;
     Source = baseException.Source;
     Detail = e.ToString();
     UserName = (Thread.CurrentPrincipal.Identity.Name ?? string.Empty);
     Date = DateTime.Now;
     // if this is an http exception, then get the status code and detailed html message provided by the host.
     var httpException = (e as HttpException);
     if (httpException != null)
     {
         StatusId = httpException.GetHttpCode();
         HtmlErrorMessage = (httpException.GetHtmlErrorMessage() ?? string.Empty);
     }
     // if the http context is available, then capture the collections that represent the state request.
     if (httpContext != null)
     {
         var httpRequest = httpContext.Request;
         ServerVariable = httpRequest.ServerVariables;
         QueryString = httpRequest.QueryString;
         Form = httpRequest.Form;
         Cookie = httpRequest.Cookies;
     }
 }
开发者ID:BclEx,项目名称:BclEx-Web,代码行数:37,代码来源:HttpError.cs

示例3: ErrorLog

    /// <summary>
    /// 紀錄錯誤訊息
    /// </summary>
    /// <param name="ex">錯誤的例外</param>
    protected void ErrorLog(Exception ex)
    {
        string ClientIP = (Request.ServerVariables["HTTP_VIA"] == null) ? Request.ServerVariables["REMOTE_ADDR"].ToString() : Request.ServerVariables["HTTP_X_FORWARDED_FOR"].ToString();
        ex = ex.GetBaseException();
        HttpBrowserCapabilities browser = Request.Browser;

        StreamWriter sw = null;

        string filePath = string.Format(@"{0}ErrorLog\err_log_" + DateTime.Now.ToString("yyyyMMdd") + ".txt", Server.MapPath("~/"));

        using (sw = File.Exists(filePath) ? new StreamWriter(filePath, true) : System.IO.File.CreateText(filePath))
        {
            sw.WriteLine("----------Strat----------");
            sw.WriteLine("----------[目前時間:" + DateTime.Now.ToString() + "]----------");
            sw.WriteLine("事件發生網頁網址:" + Request.Url);
            sw.WriteLine("事件發生路徑:" + Request.Path);
            sw.WriteLine("例外狀況訊息:" + ex.Message);
            //事件發生網頁網址

            sw.WriteLine("例外堆疊:\n" + ex.StackTrace);

            sw.WriteLine("造成錯誤的程式名稱:" + ex.Source);

            //使用者名稱
            HttpSessionState session = HttpContext.Current.Session;

            if (session != null && session["UserID"] != null)
                sw.WriteLine("使用者名稱:" + session["UserID"].ToString());
            else
                sw.WriteLine("Session已遺失!");

            sw.WriteLine("識別系統別:" + Request.UserHostAddress);

            sw.WriteLine("IP:" + ClientIP);

            sw.WriteLine("使用瀏覽器:" + browser.Type);

            sw.WriteLine("瀏覽器版本:" + browser.Version);

            sw.WriteLine("是否支援Cookie:" + (browser.Cookies ? "是" : "否"));

            sw.WriteLine("伺服器名稱:" + Request.ServerVariables["SERVER_NAME"]);

            sw.WriteLine("----------END----------\n");

            sw.Close();
        }
        Server.ClearError();
    }
开发者ID:Chao-Shiun,项目名称:OrderWeb,代码行数:53,代码来源:BasePage.cs

示例4: GetErrorPageHtml

 private string GetErrorPageHtml(Exception e)
 {
     return string.Format(ErrorPageHtmlFmt,
         Resources.SalesLogix.ExceptionPageTitle,
         Resources.SalesLogix.CannotCompleteRequest,
         e.GetBaseException().Message,
         Resources.SalesLogix.Actions,
         Resources.SalesLogix.ReturnLink,
         Resources.SalesLogix.EmailSubject,
         Request.Url,
         e.GetBaseException().Message,
         e.GetBaseException().StackTrace,
         Resources.SalesLogix.MailDetailsLink,
         Resources.SalesLogix.ShowDetails);
 }
开发者ID:ssommerfeldt,项目名称:TAC_CFX,代码行数:15,代码来源:Global.cs

示例5: HandleException

        private static HttpResponseMessage HandleException(HttpRequestMessage request, Exception exception, HttpConfiguration configuration)
        {
            Exception unwrappedException = exception.GetBaseException();
            HttpResponseException httpResponseException = unwrappedException as HttpResponseException;

            if (httpResponseException != null)
            {
                return httpResponseException.Response;
            }

            if (configuration.ShouldIncludeErrorDetail(request))
            {
                return request.CreateResponse<ExceptionSurrogate>(HttpStatusCode.InternalServerError, new ExceptionSurrogate(unwrappedException));
            }

            return new HttpResponseMessage(HttpStatusCode.InternalServerError);
        }
开发者ID:haoduotnt,项目名称:aspnetwebstack,代码行数:17,代码来源:HttpControllerDispatcher.cs

示例6: HandleException

        private static HttpResponseMessage HandleException(HttpRequestMessage request, Exception exception)
        {
            Exception unwrappedException = exception.GetBaseException();
            HttpResponseException httpResponseException = unwrappedException as HttpResponseException;

            if (httpResponseException != null)
            {
                return httpResponseException.Response;
            }

            return request.CreateErrorResponse(HttpStatusCode.InternalServerError, unwrappedException);
        }
开发者ID:reza899,项目名称:aspnetwebstack,代码行数:12,代码来源:HttpControllerDispatcher.cs

示例7: PosTest2

    public bool PosTest2()
    {
        bool retVal = true;

        TestLibrary.TestFramework.BeginScenario("PosTest2: Call GetBaseException when InnerException property is not null reference");

        try
        {
            TestException desired = new TestException();
            Exception ex = new Exception(
                TestLibrary.Generator.GetString(-55, false, c_MIN_STRING_LENGTH, c_MAX_STRING_LENGTH),
                desired);
            Exception actual = ex.GetBaseException();

            if (!desired.Equals(actual))
            {
                TestLibrary.TestFramework.LogError("002.1", "Calling GetBaseException when InnerException property is not null reference does not return current exception instance");
                TestLibrary.TestFramework.LogInformation("WARNING [LOCAL VARIABLES] desired = " + desired + ", actual = " + actual);
                retVal = false;
            }
        }
        catch (Exception e)
        {
            TestLibrary.TestFramework.LogError("002.0", "Unexpected exception: " + e);
            TestLibrary.TestFramework.LogInformation(e.StackTrace);
            retVal = false;
        }

        return retVal;
    }
开发者ID:l1183479157,项目名称:coreclr,代码行数:30,代码来源:exceptiongetbaseexception.cs

示例8: LogError

    /// <summary>
    /// Logs exceptions to the preferred database
    /// </summary>
    /// <param name="ex">The exception</param>
    /// <param name="_dsn">The database connection string</param>
    /// <param name="page">The Page object</param>
    /// <param name="showCustomErrorMessageOnPage">If set, this displays the full error text on the page to a Literal control with id="litError"</param>
    /// <param name="isSendErrorMail">Send error mail?</param>
    /// <param name="recipientEmail">Recipient's e-mail address</param>
    /// <param name="recipientName">Recipient's name</param>
    /// <param name="senderEmail">Sender's e-mail address</param>
    /// <param name="senderName">Sender's name</param>
    /// <param name="smtpServer">Name of smtp server</param>
    /// <param name="applicationName">Name of application</param>
    /// <example>Logger logger = new Logger();
    /// logger.Storage = Logger.StorageType.MySQL;
    /// logger.LogError(ex, _dsn, Page, false, true, "[email protected]", "John Dot", "[email protected]", "Bevs", "smtp.tele2.dk", "bogen.dk");</example>
    public void LogError(Exception ex, string _dsn, Page page, bool showCustomErrorMessageOnPage,
                            bool isSendErrorMail, string recipientEmail, string recipientName, string senderEmail,
                            string senderName, string smtpServer, string applicationName)
    {
        string FullErrorText = string.Empty;
        MySqlCommand mysql = null;
        MySqlDataReader reader = null;
        MySqlConnection conn = null;
        OleDb ole = null;
        SqlServer sql = null;
        IDataParameter[] p = null;

        FullErrorText = WriteEntry("ErrorMessage", ex.Message.ToString());
        FullErrorText += WriteEntry("GetBaseException", ex.GetBaseException().ToString());
        if (ex.InnerException != null)
            { FullErrorText += WriteEntry("InnerException", ex.InnerException.ToString()); }
        FullErrorText += WriteEntry("StackTrace", ex.StackTrace.ToString());
        FullErrorText += WriteEntry("GetType", ex.GetType().Name);
        FullErrorText += WriteEntry("HTTP_REFERER", HttpContext.Current.Request.ServerVariables["HTTP_REFERER"]);
        FullErrorText += WriteEntry("SCRIPT_NAME", HttpContext.Current.Request.ServerVariables["SCRIPT_NAME"]);
        FullErrorText += WriteEntry("Server.MachineName", HttpContext.Current.Server.MachineName);
        FullErrorText += WriteEntry("ErrorSource", ex.Source);

        FullErrorText += WriteHeading("Session(s)");
        try
        {
            foreach (object o in page.Session)
            {
                try { FullErrorText += WriteValue(o.ToString() + ": " + page.Session[o.ToString()]); }
                catch
                {
                    try { FullErrorText += WriteValue(o.GetType().Name + ": " + o.GetType().ToString()); }
                    catch (Exception ex2) { FullErrorText += WriteValue("Not able to read Session element due to exception: " + ex2.ToString()); }
                }
            }
        }
        catch { FullErrorText += "..on Session object"; }

        FullErrorText += WriteHeading("Application(s)");
        foreach (object o in HttpContext.Current.Application)
        {
            try { FullErrorText += WriteValue(o.ToString() +": "+ HttpContext.Current.Application[o.ToString()]); }
            catch
            {
                try { FullErrorText += WriteValue(o.GetType().Name + ": " + o.GetType().ToString()); }
                catch (Exception ex2) { FullErrorText += WriteValue("Not able to read Application element due to exception: "+ ex2.ToString()); }
            }
        }

        FullErrorText += WriteHeading("Querystring");
        foreach (object o in HttpContext.Current.Request.QueryString)
        {
            try { FullErrorText += WriteValue(o.ToString() +": "+ HttpContext.Current.Request.QueryString[o.ToString()]); }
            catch (Exception ex2) { FullErrorText += WriteValue("Not able to read Query string element due to exception: " + ex2.ToString()); }
        }

        FullErrorText += WriteHeading("Form");
        foreach (object o in HttpContext.Current.Request.Form)
        {
            try { FullErrorText += WriteValue(o.ToString() + ": " + HttpContext.Current.Request.Form[o.ToString()]); }
            catch (Exception ex2) { FullErrorText += WriteValue("Not able to read Form element due to exception: " + ex2.ToString()); }
        }

                if (_storage == StorageType.Access)
                {
                    strSQL =  " INSERT INTO [Errors]";
					strSQL += "			  ( Message, ";
					strSQL += "				Page, ";
					strSQL += "				FullErrorText, ";
					strSQL += "				ErrorDate )";
					strSQL += "	   VALUES ( ?Message, ";
					strSQL += "				?Page, ";
					strSQL += "				?FullErrorText, ";
                    strSQL += "				?ErrorDate ) ";

                    using (conn = new MySqlConnection(_dsn))
                    {
                        using (mysql = new MySqlCommand(strSQL, conn))
                        {
                            mysql.Parameters.Add("?Message", MySqlDbType.VarChar, 250).Value = "SendMail";
                            mysql.Parameters.Add("?Page", MySqlDbType.VarChar, 500).Value = "SendMail";
                            mysql.Parameters.Add("?FullErrorText", MySqlDbType.VarChar, 500).Value = FullErrorText;
                            mysql.Parameters.Add("?ErrorDate", MySqlDbType.DateTime).Value = DateTime.Now;
//.........这里部分代码省略.........
开发者ID:jdamsbo,项目名称:bevs.dk,代码行数:101,代码来源:Logger.cs


注:本文中的Exception.GetBaseException方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。