bool IExceptionHandler.Handle(ExceptionObject e) { if (!e.Handled) { MessageBox.Show(e.Exception.ToString(), "Unhandled Exception"); } return(false); // We did NOT handle the exception. Thus, we won't pretend we did. }
/// <summary> /// Handles an exception. /// </summary> /// <param name="sender">The object that sent the exception.</param> /// <param name="e">The exception.</param> public static void HandleException(object sender, Exception e) { bool handled = false; ExceptionObject o = new ExceptionObject(sender, handled, e); List <IExceptionHandler> handledBy = new List <IExceptionHandler>(); for (int i = 0; i < maxPriority; i++) { foreach (var exch in _handlers.ToArray()) { if (exch.Value == null || exch.Value.Contains(e.GetType())) { if (exch.Key.GetPriority() == i) { bool h = exch.Key.Handle(o); if (!handled) { handled = h; } if (h) { handledBy.Add(exch.Key); o.Handled = h; } } } } } if (!handled) { MinecraftModUpdater.Logger.Log(Logger.Level.Error, "Exception handler failed to handle."); MinecraftModUpdater.Logger.Log(e); throw e; //This line should NEVER excute. } string handlers = ""; foreach (IExceptionHandler handler in handledBy) { handlers += handler.GetName(); handlers += ", "; } handlers = handlers.Remove(handlers.Length - 2); MinecraftModUpdater.Logger.Log(Logger.Level.Warning, e.GetType().Name + " handled by " + handlers + "."); }
bool IExceptionHandler.Handle(ExceptionObject e) { if (!e.Handled) { MessageBox.Show(e.Exception.ToString(), "Unhandled Exception"); } return false; // We did NOT handle the exception. Thus, we won't pretend we did. }
/// <summary> /// Handles an exception. /// </summary> /// <param name="sender">The object that sent the exception.</param> /// <param name="e">The exception.</param> public static void HandleException(object sender, Exception e) { bool handled = false; ExceptionObject o = new ExceptionObject(sender, handled, e); List<IExceptionHandler> handledBy = new List<IExceptionHandler>(); for (int i = 0; i < maxPriority; i++) { foreach (var exch in _handlers.ToArray()) { if (exch.Value == null || exch.Value.Contains(e.GetType())) { if (exch.Key.GetPriority() == i) { bool h = exch.Key.Handle(o); if(!handled)handled = h; if(h) { handledBy.Add(exch.Key); o.Handled = h; } } } } } if (!handled) { MinecraftModUpdater.Logger.Log(Logger.Level.Error, "Exception handler failed to handle."); MinecraftModUpdater.Logger.Log(e); throw e; //This line should NEVER excute. } string handlers = ""; foreach(IExceptionHandler handler in handledBy) { handlers += handler.GetName(); handlers += ", "; } handlers = handlers.Remove(handlers.Length - 2); MinecraftModUpdater.Logger.Log(Logger.Level.Warning, e.GetType().Name + " handled by " + handlers + "."); }
bool IExceptionHandler.Handle(ExceptionObject e) { MinecraftModUpdater.Logger.Log(e.Exception); return true; }
bool IExceptionHandler.Handle(ExceptionObject e) { ExceptionHandler.HandleException(e.Exception, e.Sender); return true; }