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


C# Exception.GetBaseException方法代码示例

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


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

示例1: Fatal

        public static void Fatal(Exception ex, string Source)
        {
            HttpContext.Current.Response.StatusCode = 500;

            try
            {
                try
                {
                    if (ex.GetBaseException().GetType().ToString() == "MySql.Data.MySqlClient.MySqlException")
                        MySqlConnection.ClearAllPools();
                }
                catch { }

                Fatal("[" + ex.GetBaseException().GetType().ToString() + "]" + ex.GetBaseException().Message, ex.GetBaseException().ToString(), "Fatal " + ex.GetBaseException().GetType().ToString(), Source);
            }
            catch
            {
                try
                {
                    if (ex.GetType().ToString() == "MySql.Data.MySqlClient.MySqlException")
                        MySqlConnection.ClearAllPools();
                }
                catch { }

                Fatal("[" + ex.GetType().ToString() + "]" + ex.Message, ex.ToString(), "Fatal " + ex.GetType().ToString(), Source);
            }
        }
开发者ID:gageorsburn,项目名称:BlazeGames.Web,代码行数:27,代码来源:ErrorManager.cs

示例2: log

        public static void log(string level, string comp, string msg, Exception e)
        {
            if (comp == null) comp = "";
            if (msg == null) msg = "";

            var nowms = DateTimeMs.NowMs;
            var ts = nowms.ToShortDateString().PadLeft(10) + " " + nowms.ToLongTimeString().PadLeft(8) + "." + nowms.Millisecond.ToString().PadLeft(3, '0');

            msg = "["+level+"] "+ ts + "["+comp+"]  " + msg;
            if (e != null)
            {
            msg +=  "\n" + e.GetType().ToString() + ": " + e.Message +"\n"+ e.StackTrace;
            }
            if (e != null && e.GetBaseException() != null && e.GetBaseException() != e)
            {
            e = e.GetBaseException();
            msg +=  "BaseException:\n" + e.GetType().ToString() + ": " + e.Message +"\n"+ e.StackTrace;
            }
            try{
            System.Console.WriteLine(msg);
            #if __ANDROID__
            Android.Util.Log.Error("", msg);
            #endif
            if (fs != null)
            {
                fs.Write(msg+"\n");
                fs.Flush();
            }
            }catch(Exception){}
        }
开发者ID:victorchalian,项目名称:hobd,代码行数:30,代码来源:Logger.cs

示例3: UnhandledExcp

 public UnhandledExcp(Exception excp)
 {
     InitializeComponent();
     detailText.Text = excp.ToString();
     if (excp.GetBaseException() != null)
         detailText.AppendText(Environment.NewLine + "--- BASE ---" + Environment.NewLine + excp.GetBaseException().ToString());
 }
开发者ID:karno,项目名称:Typict,代码行数:7,代码来源:UnhandledExcp.cs

示例4: OnUnhandledException

 private void OnUnhandledException(Exception exception)
 {
     MessageBox.Show(
         $"An error occured:{Environment.NewLine}{exception.GetBaseException().GetType().Name}: {exception.GetBaseException().Message}",
         "Oops, an error occured",
         MessageBoxButton.OK,
         MessageBoxImage.Error);
 }
开发者ID:mytho123,项目名称:spotyscraper,代码行数:8,代码来源:App.xaml.cs

示例5: AddValidationErrors

 /// <summary>
 /// Add to the model state a list of error that came from properties. If the property name
 /// is empty, this one will be without property (general)
 /// </summary>
 /// <param name="modelState">State of the model.</param>
 /// <param name="propertyErrors">The property errors.</param>
 public static void AddValidationErrors(this ModelStateDictionary modelState, Exception exception)
 {
     if (exception is IValidationErrors)
     {
         foreach (var databaseValidationError in (exception as ValidationErrors).Errors)
         {
             modelState.AddModelError(databaseValidationError.PropertyName ?? string.Empty, databaseValidationError.PropertyExceptionMessage);
         }
     }
     else
     {
         modelState.AddModelError(string.Empty, exception.Message + (exception.Message != exception.GetBaseException().Message ? "\r\n" + exception.GetBaseException().Message : ""));
     }
 }
开发者ID:LeMinhHiep,项目名称:BPortals,代码行数:20,代码来源:ControllersExtensions.cs

示例6: FromException

        public static JsonObject FromException(Exception e, bool includeStackTrace)
        {
            if (e == null)
                throw new ArgumentNullException("e");

            JsonObject error = new JsonObject();
            error.Put("name", "JSONRPCError");
            error.Put("message", e.GetBaseException().Message);

            if (includeStackTrace)
                error.Put("stackTrace", e.StackTrace);

            JsonArray errors = new JsonArray();
                
            do
            {
                errors.Put(ToLocalError(e));
                e = e.InnerException;
            }
            while (e != null);
            
            error.Put("errors", errors);
            
            return error;
        }
开发者ID:db48x,项目名称:KeeFox,代码行数:25,代码来源:JsonRpcError.cs

示例7: showError

        public static void showError(Exception ex, string Infotext, Boolean ForceEnd = false)
        {
            string Info;

            // first log the complete exception
            _logger.Log(Infotext, true);
            _logger.Log(ex.ToString(), true);
            _logger.Log(ex.Message, true);
            _logger.Log(ex.StackTrace, true);
            if (ex.InnerException != null)
                _logger.Log(ex.InnerException.ToString(), true);

            if (Infotext.Trim().Length > 0)
                Info = Infotext + Environment.NewLine + Environment.NewLine + ex.Message + Environment.NewLine;
            else
                Info = ex.Message + Environment.NewLine;

            if (ex.InnerException != null)
                Info += Environment.NewLine + ex.GetBaseException().Message;

            Info += string.Format("{0}{0}(see detailed info in logfile \"{1}\")", Environment.NewLine, _logger.logPathName);
            Info += "Create a dump file ?";

            if (MessageBox.Show(Info, "Exception occured",MessageBoxButtons.OK, MessageBoxIcon.Exclamation) == DialogResult.Yes)
               Program.CreateMiniDump("RegulatedNoiseDump.dmp");
        }
开发者ID:carriercomm,项目名称:ED-IBE,代码行数:26,代码来源:centralizedErrorhandler.cs

示例8: processError

        public static void processError(Exception ex, string Infotext, bool noAsking)
        {
            string Info;

            // first log the complete exception
            _logger.Log(Infotext, true);
            _logger.Log(ex.ToString(), true);
            _logger.Log(ex.Message, true);
            _logger.Log(ex.StackTrace, true);
            if (ex.InnerException != null)
                _logger.Log(ex.InnerException.ToString(), true);

            if (Infotext.Trim().Length > 0)
                Info = Infotext + Environment.NewLine + Environment.NewLine + ex.Message + Environment.NewLine;
            else
                Info = ex.Message + Environment.NewLine;

            if (ex.InnerException != null)
                Info += Environment.NewLine + ex.GetBaseException().Message;

            Info += string.Format("{0}{0}(see detailed info in logfile \"{1}\")", Environment.NewLine, _logger.logPathName);

            Info += string.Format("{0}{0}Suppress exception ? (App can be unstable!)", Environment.NewLine);

            Program.CreateMiniDump("RegulatedNoiseDump_handled.dmp");

            // ask user what to do
            if (noAsking || (MessageBox.Show(Info, "Exception occured",MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button2) == DialogResult.No))
            {
                MessageBox.Show("Fatal error.\r\n\r\nA dump file (\"RegulatedNoiseDump_handled.dmp\" has been created in your RegulatedNoise directory.  \r\n\r\nPlease place this in a file-sharing service such as Google Drive or Dropbox, then link to the file in the Frontier forums or on the GitHub archive.  This will allow the developers to fix this problem.  \r\n\r\nThanks, and sorry about the crash...");
                Environment.Exit(-1);
            }
        }
开发者ID:carriercomm,项目名称:ED-IBE,代码行数:33,代码来源:centralizedErrorhandler.cs

示例9: Error

        public Error(Exception exception, IOwinContext owinContext)
        {
            if (exception == null)
                throw new ArgumentNullException(nameof(exception));

            Exception = exception;
            var baseException = exception.GetBaseException();

            HostName = EnvironmentUtilities.GetMachineNameOrDefault();
            TypeName = baseException.GetType().FullName;
            Message = baseException.Message;
            Source = baseException.Source;
            Detail = exception.ToString();
            User = Thread.CurrentPrincipal.Identity.Name ?? string.Empty;
            Time = DateTimeOffset.Now;

            StatusCode = owinContext.Response.StatusCode;

            var webUser = owinContext.Authentication.User;
            if (!string.IsNullOrEmpty(webUser?.Identity?.Name))
            {
                User = webUser.Identity.Name;
            }

            ServerEnvironment = owinContext.Environment.ToDictionary(pair => pair.Key, pair => pair.Value?.ToString() ?? string.Empty);
            Headers = owinContext.Request.Headers.ToDictionary(pair => pair.Key, pair => pair.Value);
            Query = owinContext.Request.Query.ToDictionary(pair => pair.Key, pair => pair.Value);
            Cookies = owinContext.Request.Cookies.ToDictionary(pair => pair.Key, pair => pair.Value);
            ApplicationName = AppDomain.CurrentDomain.FriendlyName;
        }
开发者ID:Eonix,项目名称:Elmo,代码行数:30,代码来源:Error.cs

示例10: AddException

        public static void AddException(Exception exception, string comments = null, LogExceptionLevel level = LogExceptionLevel.Low)
        {
            if (exception == null)
                return;

            try
            {
                var baseException = exception.GetBaseException();
                using (var db = new DbEntities())
                {
                    db.InsertException(new LogException()
                    {
                        Comments = comments,
                        ExceptionLevel = (short)level,
                        InsertionTime = DateTime.Now,
                        Message = exception.Message,
                        InnerException = (exception.InnerException != null) ? exception.InnerException.Message : null,
                        StackTrace = exception.StackTrace,
                        TargetSite = (exception.TargetSite != null) ? exception.TargetSite.Name : null,
                        Source = exception.Source,
                        BaseException = (baseException != null) ? baseException.Message : null
                    });
                }
            }
            catch { }
        }
开发者ID:Regisfra,项目名称:Regisfra.WebApp,代码行数:26,代码来源:Utils.cs

示例11: VLogServerSideError

        /// <summary>
        ///     Initializes a new instance of the <see cref="VLogServerSideError"/> class.
        /// from a given <see cref="Exception"/> instance and 
        /// <see cref="HttpContext"/> instance representing the HTTP 
        /// context during the exception.
        /// </summary>
        /// <param name="exception">The occurred server side exception</param>
        public VLogServerSideError(Exception exception)
            : this()
        {
            HttpContext context = HttpContext.Current;
            if (exception != null && context != null)
            {
                Exception baseException = exception.GetBaseException();

                this.ErrorMessage = baseException.GetErrorMessage();
                this.ErrorDetails = exception.GetErrorErrorDetails();

                // Sets an object of a uniform resource identifier properties
                this.SetAdditionalHttpContextInfo(context);
                this.SetAdditionalExceptionInfo(exception);

                // If this is an HTTP exception, then get the status code
                // and detailed HTML message provided by the host.
                var httpException = exception as HttpException;
                if (httpException != null)
                {
                    this.ErrorCode = httpException.GetHttpCode();

                    VLogErrorCode errorcoderule;

                    if (VLog.WebErrorCodes.TryGetValue(this.ErrorCode, out errorcoderule) && !errorcoderule.ExcludeFromLogging)
                    {
                        this.AddHttpExceptionData(errorcoderule, context, httpException, errorcoderule);
                    }
                }
            }
        }
开发者ID:MGramolini,项目名称:vodca,代码行数:38,代码来源:VLogServerSideError.cs

示例12: BuildWebSocketError

        public static string BuildWebSocketError(Exception ex)
        {
            ex = ex.GetBaseException();

            if ((uint)ex.HResult == 0x800C000EU)
            {
                // INET_E_SECURITY_PROBLEM - our custom certificate validator rejected the request.
                return "Error: Rejected by custom certificate validation.";
            }

            WebErrorStatus status = WebSocketError.GetStatus(ex.HResult);

            // Normally we'd use the HResult and status to test for specific conditions we want to handle.
            // In this sample, we'll just output them for demonstration purposes.
            switch (status)
            {
                case WebErrorStatus.CannotConnect:
                case WebErrorStatus.NotFound:
                case WebErrorStatus.RequestTimeout:
                    return "Cannot connect to the server. Please make sure " +
                        "to run the server setup script before running the sample.";

                case WebErrorStatus.Unknown:
                    return "COM error: " + ex.HResult;

                default:
                    return "Error: " + status;
            }
        }
开发者ID:polarapfel,项目名称:Windows-universal-samples,代码行数:29,代码来源:SampleConfiguration.cs

示例13: OnException

        protected override void OnException(ExceptionContext filterContext)
        {
            String Errormsg = String.Empty;
            Exception unhandledException = new Exception("BASE ERROR");
            if (Server.GetLastError() != null)
                unhandledException = Server.GetLastError();
            else
                unhandledException = filterContext.Exception;
            Exception httpException = unhandledException as Exception;
            Errormsg = "發生例外網頁:{0}錯誤訊息:{1}";
            if (httpException != null /*&& !httpException.GetType().IsAssignableFrom(typeof(HttpException))*/)
            {
                Errormsg = String.Format(Errormsg, Request.Path + Environment.NewLine,unhandledException.GetBaseException().ToString() + Environment.NewLine);

                Url = System.Web.HttpContext.Current.Request.Url.PathAndQuery;
                controller = Convert.ToString(ControllerContext.RouteData.Values["controller"]);
                action = Convert.ToString(ControllerContext.RouteData.Values["action"]);
                area = Convert.ToString(ControllerContext.RouteData.DataTokens["area"]);
                NLog.Logger logger = LogManager.GetCurrentClassLogger();
                logger.Error(Url + "|controller|" + controller + "|action|" + action + "|area|" + area + "|" + Errormsg);

            }
            base.OnException(filterContext);
            filterContext.ExceptionHandled = true;
        }
开发者ID:yang7129,项目名称:ASPNETSolution,代码行数:25,代码来源:baseController.cs

示例14: WriteToEventLog

        private static void WriteToEventLog(Exception ex)
        {
            const string source = "Health.Direct.Config.Service";

            EventLogHelper.WriteError(source, ex.Message);
            EventLogHelper.WriteError(source, ex.GetBaseException().ToString());
        }
开发者ID:DM-TOR,项目名称:nhin-d,代码行数:7,代码来源:RecordRetrievalService.svc.cs

示例15: GetBaseCause

 string GetBaseCause( Exception ex )
 {
     var inEx = ex.GetBaseException();
     string error = null;
     error = string.Format( "{1}{0}{2}", Environment.NewLine, inEx.Message, inEx.StackTrace );
     return error;
 }
开发者ID:m-abubakar,项目名称:logrotatewin,代码行数:7,代码来源:LogrotateService.cs


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