/// <summary> /// All unhandled exceptions will ultimately end up here, (hopefully) providing a single /// point of contact for what action to take when it happens. /// /// Exceptions are divided into 2 categories. Non-CLR compliant exceptions, (usually the result /// of calling outside the .NET framework) CLR compliant exceptions. /// </summary> /// <param name="anyException"></param> public static void HandleUncaughtException(object anyException) { Exception exception = anyException as Exception; if (exception == null) // Non CLR compliant exception { // Non clr message UnexpectedErrorMessage.Show(new Exception("A non CLR exception has occurred and been unhandled.")); return; } else { UnexpectedErrorMessage.Show(new ForeGroundWindow(), exception); return; } }
/// <summary> /// Static version of Show that allows you to specify the Type of the /// UnexpectedErrorMessage and have the method automatically create /// and dispose the instance /// </summary> /// <param name="errorType">type of error (must be derived from UnexpectedErrorMessage)</param> /// <param name="owner">window owner for showing message</param> /// <param name="rootCause">root cause (can be null)</param> /// <param name="args">format arguments (optional)</param> public static void Show(Type errorType, IWin32Window owner, Exception rootCause, params object[] args) { // verify calling semantics if (errorType.IsSubclassOf(typeof(UnexpectedErrorMessage))) { // create instance of error type using (UnexpectedErrorMessage errorMessage = Activator.CreateInstance(errorType) as UnexpectedErrorMessage) { errorMessage.ShowMessage(owner, rootCause, args); } } else { Debug.Fail("Type passed to ShowErrorMessage (" + errorType.Name + ") is not a subclass of UnexpectedErrorMessage"); } }
public static void Show(IWin32Window owner, Exception rootCause, string title) { // create instance of error type using (UnexpectedErrorMessage errorMessage = new UnexpectedErrorMessage()) { errorMessage.Title = title; errorMessage.ShowMessage(owner, rootCause, new string[0]); } }