mirror of
https://github.com/kwsch/PKHeX
synced 2024-11-10 22:54:14 +00:00
12c46d18a8
VS wouldn't break at the line that threw the exception; only have the custom exception handling for release builds (ie the CI server & posted builds). makes it easy to debug again
85 lines
3.3 KiB
C#
85 lines
3.3 KiB
C#
using System;
|
|
using System.Threading;
|
|
using System.Windows.Forms;
|
|
|
|
namespace PKHeX.WinForms
|
|
{
|
|
internal static class Program
|
|
{
|
|
/// <summary>
|
|
/// The main entry point for the application.
|
|
/// </summary>
|
|
[STAThread]
|
|
private static void Main()
|
|
{
|
|
#if !DEBUG
|
|
// Add the event handler for handling UI thread exceptions to the event.
|
|
Application.ThreadException += UIThreadException;
|
|
|
|
// Set the unhandled exception mode to force all Windows Forms errors to go through our handler.
|
|
Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);
|
|
|
|
// Add the event handler for handling non-UI thread exceptions to the event.
|
|
AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
|
|
#endif
|
|
|
|
// Run the application
|
|
Application.EnableVisualStyles();
|
|
Application.SetCompatibleTextRenderingDefault(false);
|
|
Application.Run(new Main());
|
|
}
|
|
|
|
// Handle the UI exceptions by showing a dialog box, and asking the user whether or not they wish to abort execution.
|
|
private static void UIThreadException(object sender, ThreadExceptionEventArgs t)
|
|
{
|
|
DialogResult result = DialogResult.Cancel;
|
|
try
|
|
{
|
|
// Todo: make this translatable
|
|
ErrorWindow.ShowErrorDialog("An unhandled exception has occurred.\nYou can continue running PKHeX, but please report this error.", t.Exception, true);
|
|
}
|
|
catch
|
|
{
|
|
try
|
|
{
|
|
// Todo: make this translatable
|
|
MessageBox.Show("A fatal error has occurred in PKHeX, and the details could not be displayed. Please report this to the author.", "PKHeX Error", MessageBoxButtons.OK, MessageBoxIcon.Stop);
|
|
}
|
|
finally
|
|
{
|
|
Application.Exit();
|
|
}
|
|
}
|
|
|
|
// Exits the program when the user clicks Abort.
|
|
if (result == DialogResult.Abort)
|
|
Application.Exit();
|
|
}
|
|
|
|
// Handle the UI exceptions by showing a dialog box, and asking the user whether
|
|
// or not they wish to abort execution.
|
|
// NOTE: This exception cannot be kept from terminating the application - it can only
|
|
// log the event, and inform the user about it.
|
|
private static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
|
|
{
|
|
try
|
|
{
|
|
var ex = (Exception)e.ExceptionObject;
|
|
// Todo: make this translatable
|
|
ErrorWindow.ShowErrorDialog("An unhandled exception has occurred.\nPKHeX must now close.", ex, false);
|
|
}
|
|
catch
|
|
{
|
|
try
|
|
{
|
|
// Todo: make this translatable
|
|
MessageBox.Show("A fatal non-UI error has occurred in PKHeX, and the details could not be displayed. Please report this to the author.", "PKHeX Error", MessageBoxButtons.OK, MessageBoxIcon.Stop);
|
|
}
|
|
finally
|
|
{
|
|
Application.Exit();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|