private static ProcessFlow HandledExceptionLogger(Exception exp, StackFrame[] callStackFrames) { // // If number of errors exist in cache more than MaxQueuedError then skip new errors if (CacheController.SdfManager.ErrorIds.Count > ErrorHandlingOption.MaxQueuedError) { if (!ErrorHandlingOption.AtSentState && ErrorHandlingOption.EnableNetworkSending) { Task.Run(async() => await CacheController.CheckStateAsync()); } return(ProcessFlow.Continue); } if (!ErrorHandlingOption.ReportHandledExceptions) // Do not store exception data { return(ProcessFlow.Continue); } bool snapshot; // // ---------------------------- Filter exception --------------------------------------- if (Filter.IsFiltering(exp, callStackFrames, out snapshot)) { return(ProcessFlow.Continue); } // // initial the error object by additional data var error = new Error(exp, callStackFrames, snapshot); // // Store Error object if (ErrorHandlingOption.LogOnTheFly) { Task.Run(async() => await error.SendToServer()); } else { CacheController.CacheTheError(error); } return(ProcessFlow.Continue); }
private static ProcessFlow UnhandledExceptionLogger(Exception exp, StackFrame[] callStackFrames, String errorTitle) { // // If number of errors exist in cache more than MaxQueuedError then skip new errors if (CacheController.SdfManager.ErrorIds.Count > ErrorHandlingOption.MaxQueuedError) { if (!ErrorHandlingOption.AtSentState && ErrorHandlingOption.EnableNetworkSending) { Task.Run(async() => await CacheController.CheckStateAsync()); } return(ErrorHandlingOption.ExitApplicationImmediately); } bool snapshot; // // ---------------------------- Filter exception --------------------------------------- if (Filter.IsFiltering(exp, callStackFrames, out snapshot)) { return(ErrorHandlingOption.ExitApplicationImmediately); } // // initial the error object by additional data var error = new Error(exp, callStackFrames, snapshot) { IsHandled = false }; // // Store Error object CacheController.CacheTheError(error); // // Handle 'OnShowUnhandledError' events OnShowUnhandledError(exp, new UnhandledErrorEventArgs(error)); // // Alert Unhandled Error if (ErrorHandlingOption.DisplayUnhandledExceptions) { if (ErrorHandlingOption.DisplayDeveloperUI) { var msgResult = ProcessFlow.Continue; var staThread = new Thread(() => { var msg = new ExceptionViewer { Title = errorTitle }; msg.Dispatcher.Invoke(() => msgResult = msg.ShowDialog(exp)); }); staThread.SetApartmentState(ApartmentState.STA); staThread.Start(); staThread.Join(); return(msgResult); } // // ELSE: MessageBox.Show(error.Message, errorTitle, MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, MessageBoxOptions.ServiceNotification); } return(ErrorHandlingOption.ExitApplicationImmediately); }
public static Error RaiseLog(this Exception exp, bool isHandled = true, String errorTitle = "UnHandled Exception") { try { // // If number of errors exist in cache more than MaxQueuedError then skip new errors if (SqlCompactEditionManager.ErrorIds.Count > ErrorHandlingOption.MaxQueuedError) { if (!ErrorHandlingOption.AtSentState && ErrorHandlingOption.EnableNetworkSending) { Task.Run(async() => await CacheController.CheckStateAsync()); } return(null); } if (isHandled && !ErrorHandlingOption.ReportHandledExceptions) { return(null); } // // In Corrupted State one method more than normal modes. var skipCount = ErrorHandlingOption.HandleProcessCorruptedStateExceptions ? 3 : 2; // // Create call stack till this method // 1# Handled Exception ---> Create from this stack trace (by skip(2): RaiseLog and FirstChance Method) // 2# Unhandled Exception & Null Exception.StackTrace ---> Create from this stack trace (by skip(2): RaiseLog and UnhandledException Method) // 3# Unhandled Exception & Not Null Exception ---> Create from exp stack trace var callStackFrames = !isHandled && exp.StackTrace != null // 3# ? new StackTrace(exp, true).GetFrames() // 3#: Raise from UnhandledException : new StackTrace(skipCount, true).GetFrames(); // 1# or 2#: Raise from FirstChance bool snapshot = ErrorHandlingOption.Snapshot; #region ---------------------------- Filter exception --------------------------------------- if (ErrorHandlingOption.FilterExceptions) { // // Find exception type: var expType = exp.GetType(); // // Is exception within non-snapshot list? (yes => remove snapshot option) if (Filter.NonSnapshotExceptionTypes.Any(x => x == expType)) { snapshot = false; } // // Is exception in exempted list? if (Filter.ExemptedExceptionTypes.Any(x => x == expType) || Filter.ExemptedCodeScopes.Any(x => x.IsCallFromThisPlace(callStackFrames))) { return(null); } // // Must be exception occurred from these code scopes to that raised by handler. if (Filter.JustRaiseErrorCodeScopes.Count > 0 && !Filter.JustRaiseErrorCodeScopes.Any(x => x.IsCallFromThisPlace(callStackFrames))) { return(null); } } if (ErrorHandlingOption.CacheCodeScope.IsCallFromThisPlace(callStackFrames)) { return(null); } #endregion ------------------------------------------------------------------------------------ // // initial the error object by additional data var error = new Error(exp, callStackFrames, snapshot); if (!isHandled) // Is Unhandled Exception ? { error.IsHandled = false; // // Handle 'OnShowUnhandledError' events OnShowUnhandledError(exp, new UnhandledErrorEventArgs(error)); // // Alert Unhandled Error if (ErrorHandlingOption.DisplayUnhandledExceptions) { MessageBox.Show(exp.Message, errorTitle, MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, MessageBoxOptions.ServiceNotification); } } CacheController.CacheTheError(error); return(error); } finally { if (!isHandled && ErrorHandlingOption.ExitApplicationImmediately) { Environment.Exit(0); } } }