當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。