Skip to content

Commit

Permalink
Add FatalErrorHandler
Browse files Browse the repository at this point in the history
Allows us to display a message to the user and quit when an
unrecoverable error occurs.

Can't really be tested unfortunately.
  • Loading branch information
blowfishpro committed Oct 5, 2017
1 parent d1975db commit 78d4635
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
38 changes: 38 additions & 0 deletions ModuleManager/FatalErrorHandler.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
using System;
using UnityEngine;

namespace ModuleManager
{
public static class FatalErrorHandler
{
public static void HandleFatalError(string message)
{
try
{
PopupDialog.SpawnPopupDialog(new Vector2(0.5f, 0.5f),
new Vector2(0.5f, 0.5f),
new MultiOptionDialog(
"ModuleManagerFatalError",
$"ModuleManager has encountered a fatal error and KSP needs to close.\n\n{message}\n\nPlease see KSP's log for addtional details",
"ModuleManager - Fatal Error",
HighLogic.UISkin,
new Rect(0.5f, 0.5f, 500f, 60f),
new DialogGUIFlexibleSpace(),
new DialogGUIHorizontalLayout(
new DialogGUIFlexibleSpace(),
new DialogGUIButton("Quit", Application.Quit, 140.0f, 30.0f, true),
new DialogGUIFlexibleSpace()
)
),
true,
HighLogic.UISkin);
}
catch(Exception ex)
{
Debug.LogError("Exception while trying to create the fatal exception dialog");
Debug.LogException(ex);
Application.Quit();
}
}
}
}
1 change: 1 addition & 0 deletions ModuleManager/ModuleManager.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
<Compile Include="Extensions\StringExtensions.cs" />
<Compile Include="Extensions\UrlConfigExtensions.cs" />
<Compile Include="IPatchProgress.cs" />
<Compile Include="FatalErrorHandler.cs" />
<Compile Include="Logging\ExceptionMessage.cs" />
<Compile Include="Logging\IBasicLogger.cs" />
<Compile Include="Logging\ILogMessage.cs" />
Expand Down

0 comments on commit 78d4635

Please sign in to comment.