Merge pull request #1159 from mRemoteNG/1123_handle_unhandled_exceptions

Added unhandled exception window
This commit is contained in:
David Sparer
2018-12-05 16:31:36 -06:00
committed by GitHub
7 changed files with 470 additions and 0 deletions

View File

@@ -24,6 +24,7 @@ namespace mRemoteNG.App
private static void StartApplication()
{
CatchAllUnhandledExceptions();
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(FrmMain.Default);
@@ -69,5 +70,24 @@ namespace mRemoteNG.App
}
return windowHandle;
}
private static void CatchAllUnhandledExceptions()
{
Application.ThreadException += ApplicationOnThreadException;
Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);
AppDomain.CurrentDomain.UnhandledException += CurrentDomainOnUnhandledException;
}
private static void ApplicationOnThreadException(object sender, ThreadExceptionEventArgs e)
{
var window = new UnhandledExceptionWindow(e.Exception, false);
window.ShowDialog(FrmMain.Default);
}
private static void CurrentDomainOnUnhandledException(object sender, UnhandledExceptionEventArgs e)
{
var window = new UnhandledExceptionWindow(e.ExceptionObject as Exception, e.IsTerminating);
window.ShowDialog(FrmMain.Default);
}
}
}

View File

@@ -159,6 +159,24 @@ namespace mRemoteNG {
}
}
/// <summary>
/// Looks up a localized string similar to This exception will force mRemoteNG to close.
/// </summary>
internal static string ExceptionForcesmRemoteNGToClose {
get {
return ResourceManager.GetString("ExceptionForcesmRemoteNGToClose", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Exception Message.
/// </summary>
internal static string ExceptionMessage {
get {
return ResourceManager.GetString("ExceptionMessage", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Filter search matches in connection tree.
/// </summary>
@@ -195,6 +213,15 @@ namespace mRemoteNG {
}
}
/// <summary>
/// Looks up a localized string similar to mRemoteNG Unhandled Exception.
/// </summary>
internal static string mRemoteNGUnhandledException {
get {
return ResourceManager.GetString("mRemoteNGUnhandledException", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Prompt to unlock credential repositories on startup.
/// </summary>
@@ -249,6 +276,15 @@ namespace mRemoteNG {
}
}
/// <summary>
/// Looks up a localized string similar to Stack trace.
/// </summary>
internal static string StackTrace {
get {
return ResourceManager.GetString("StackTrace", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to About.
/// </summary>
@@ -7777,6 +7813,15 @@ namespace mRemoteNG {
}
}
/// <summary>
/// Looks up a localized string similar to An unhandled exception has occurred.
/// </summary>
internal static string UnhandledExceptionOccured {
get {
return ResourceManager.GetString("UnhandledExceptionOccured", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Unlock.
/// </summary>

View File

@@ -2718,6 +2718,21 @@ This page will walk you through the process of upgrading your connections file o
<data name="ChangeConnectionResolutionError" xml:space="preserve">
<value>An error occurred while trying to change the connection resolution to host '{0}'</value>
</data>
<data name="StackTrace" xml:space="preserve">
<value>Stack trace</value>
</data>
<data name="ExceptionMessage" xml:space="preserve">
<value>Exception Message</value>
</data>
<data name="mRemoteNGUnhandledException" xml:space="preserve">
<value>mRemoteNG Unhandled Exception</value>
</data>
<data name="UnhandledExceptionOccured" xml:space="preserve">
<value>An unhandled exception has occurred</value>
</data>
<data name="ExceptionForcesmRemoteNGToClose" xml:space="preserve">
<value>This exception will force mRemoteNG to close</value>
</data>
<data name="strMenuCopyHostname" xml:space="preserve">
<value>Copy Hostname</value>
</data>

View File

@@ -0,0 +1,193 @@
namespace mRemoteNG.UI.Forms
{
partial class UnhandledExceptionWindow
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.tableLayoutPanel1 = new System.Windows.Forms.TableLayoutPanel();
this.labelExceptionCaught = new System.Windows.Forms.Label();
this.buttonClose = new System.Windows.Forms.Button();
this.textBoxStackTrace = new System.Windows.Forms.TextBox();
this.labelStackTraceHeader = new System.Windows.Forms.Label();
this.labelExceptionMessageHeader = new System.Windows.Forms.Label();
this.textBoxExceptionMessage = new System.Windows.Forms.TextBox();
this.buttonCopyAll = new System.Windows.Forms.Button();
this.labelExceptionIsFatalHeader = new System.Windows.Forms.Label();
this.tableLayoutPanel1.SuspendLayout();
this.SuspendLayout();
//
// tableLayoutPanel1
//
this.tableLayoutPanel1.ColumnCount = 4;
this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 30F));
this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 100F));
this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 80F));
this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 30F));
this.tableLayoutPanel1.Controls.Add(this.labelExceptionCaught, 1, 0);
this.tableLayoutPanel1.Controls.Add(this.buttonClose, 2, 6);
this.tableLayoutPanel1.Controls.Add(this.textBoxStackTrace, 1, 5);
this.tableLayoutPanel1.Controls.Add(this.labelStackTraceHeader, 1, 4);
this.tableLayoutPanel1.Controls.Add(this.labelExceptionMessageHeader, 1, 2);
this.tableLayoutPanel1.Controls.Add(this.textBoxExceptionMessage, 1, 3);
this.tableLayoutPanel1.Controls.Add(this.buttonCopyAll, 1, 6);
this.tableLayoutPanel1.Controls.Add(this.labelExceptionIsFatalHeader, 1, 1);
this.tableLayoutPanel1.Dock = System.Windows.Forms.DockStyle.Fill;
this.tableLayoutPanel1.Location = new System.Drawing.Point(0, 0);
this.tableLayoutPanel1.Name = "tableLayoutPanel1";
this.tableLayoutPanel1.RowCount = 7;
this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 30F));
this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle());
this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 20F));
this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 20F));
this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 20F));
this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 80F));
this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 30F));
this.tableLayoutPanel1.Size = new System.Drawing.Size(534, 311);
this.tableLayoutPanel1.TabIndex = 0;
//
// labelExceptionCaught
//
this.labelExceptionCaught.AutoSize = true;
this.tableLayoutPanel1.SetColumnSpan(this.labelExceptionCaught, 2);
this.labelExceptionCaught.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.labelExceptionCaught.Location = new System.Drawing.Point(33, 0);
this.labelExceptionCaught.Name = "labelExceptionCaught";
this.labelExceptionCaught.Size = new System.Drawing.Size(311, 20);
this.labelExceptionCaught.TabIndex = 3;
this.labelExceptionCaught.Text = "An unhandled exception has occurred";
//
// buttonClose
//
this.buttonClose.DialogResult = System.Windows.Forms.DialogResult.Cancel;
this.buttonClose.Dock = System.Windows.Forms.DockStyle.Right;
this.buttonClose.Location = new System.Drawing.Point(427, 284);
this.buttonClose.Name = "buttonClose";
this.buttonClose.Size = new System.Drawing.Size(74, 24);
this.buttonClose.TabIndex = 1;
this.buttonClose.Text = "Close";
this.buttonClose.UseVisualStyleBackColor = true;
this.buttonClose.Click += new System.EventHandler(this.buttonClose_Click);
//
// textBoxStackTrace
//
this.tableLayoutPanel1.SetColumnSpan(this.textBoxStackTrace, 2);
this.textBoxStackTrace.Dock = System.Windows.Forms.DockStyle.Fill;
this.textBoxStackTrace.Location = new System.Drawing.Point(33, 128);
this.textBoxStackTrace.Multiline = true;
this.textBoxStackTrace.Name = "textBoxStackTrace";
this.textBoxStackTrace.ReadOnly = true;
this.textBoxStackTrace.ScrollBars = System.Windows.Forms.ScrollBars.Vertical;
this.textBoxStackTrace.Size = new System.Drawing.Size(468, 150);
this.textBoxStackTrace.TabIndex = 0;
//
// labelStackTraceHeader
//
this.labelStackTraceHeader.AutoSize = true;
this.labelStackTraceHeader.Dock = System.Windows.Forms.DockStyle.Bottom;
this.labelStackTraceHeader.Location = new System.Drawing.Point(33, 112);
this.labelStackTraceHeader.Name = "labelStackTraceHeader";
this.labelStackTraceHeader.Size = new System.Drawing.Size(388, 13);
this.labelStackTraceHeader.TabIndex = 4;
this.labelStackTraceHeader.Text = "Stack trace";
//
// labelExceptionMessageHeader
//
this.labelExceptionMessageHeader.AutoSize = true;
this.labelExceptionMessageHeader.Dock = System.Windows.Forms.DockStyle.Bottom;
this.labelExceptionMessageHeader.Location = new System.Drawing.Point(33, 53);
this.labelExceptionMessageHeader.Name = "labelExceptionMessageHeader";
this.labelExceptionMessageHeader.Size = new System.Drawing.Size(388, 13);
this.labelExceptionMessageHeader.TabIndex = 5;
this.labelExceptionMessageHeader.Text = "Exception message";
//
// textBoxExceptionMessage
//
this.tableLayoutPanel1.SetColumnSpan(this.textBoxExceptionMessage, 2);
this.textBoxExceptionMessage.Dock = System.Windows.Forms.DockStyle.Fill;
this.textBoxExceptionMessage.Location = new System.Drawing.Point(33, 69);
this.textBoxExceptionMessage.Multiline = true;
this.textBoxExceptionMessage.Name = "textBoxExceptionMessage";
this.textBoxExceptionMessage.ReadOnly = true;
this.textBoxExceptionMessage.ScrollBars = System.Windows.Forms.ScrollBars.Vertical;
this.textBoxExceptionMessage.Size = new System.Drawing.Size(468, 33);
this.textBoxExceptionMessage.TabIndex = 6;
//
// buttonCopyAll
//
this.buttonCopyAll.Dock = System.Windows.Forms.DockStyle.Right;
this.buttonCopyAll.Location = new System.Drawing.Point(346, 284);
this.buttonCopyAll.Name = "buttonCopyAll";
this.buttonCopyAll.Size = new System.Drawing.Size(75, 24);
this.buttonCopyAll.TabIndex = 7;
this.buttonCopyAll.Text = "Copy All";
this.buttonCopyAll.UseVisualStyleBackColor = true;
this.buttonCopyAll.Click += new System.EventHandler(this.buttonCopyAll_Click);
//
// labelExceptionIsFatalHeader
//
this.labelExceptionIsFatalHeader.AutoSize = true;
this.tableLayoutPanel1.SetColumnSpan(this.labelExceptionIsFatalHeader, 2);
this.labelExceptionIsFatalHeader.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.labelExceptionIsFatalHeader.Location = new System.Drawing.Point(33, 30);
this.labelExceptionIsFatalHeader.Name = "labelExceptionIsFatalHeader";
this.labelExceptionIsFatalHeader.Size = new System.Drawing.Size(281, 16);
this.labelExceptionIsFatalHeader.TabIndex = 8;
this.labelExceptionIsFatalHeader.Text = "This exception will force mRemoteNG to close";
//
// UnhandledExceptionWindow
//
this.AutoScaleDimensions = new System.Drawing.SizeF(96F, 96F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Dpi;
this.CancelButton = this.buttonClose;
this.ClientSize = new System.Drawing.Size(534, 311);
this.ControlBox = false;
this.Controls.Add(this.tableLayoutPanel1);
this.MinimumSize = new System.Drawing.Size(550, 350);
this.Name = "UnhandledExceptionWindow";
this.ShowInTaskbar = false;
this.SizeGripStyle = System.Windows.Forms.SizeGripStyle.Hide;
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
this.Text = "mRemoteNG Unhandled Exception";
this.tableLayoutPanel1.ResumeLayout(false);
this.tableLayoutPanel1.PerformLayout();
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.TableLayoutPanel tableLayoutPanel1;
private System.Windows.Forms.TextBox textBoxStackTrace;
private System.Windows.Forms.Button buttonClose;
private System.Windows.Forms.Label labelExceptionCaught;
private System.Windows.Forms.Label labelStackTraceHeader;
private System.Windows.Forms.Label labelExceptionMessageHeader;
private System.Windows.Forms.TextBox textBoxExceptionMessage;
private System.Windows.Forms.Button buttonCopyAll;
private System.Windows.Forms.Label labelExceptionIsFatalHeader;
}
}

View File

@@ -0,0 +1,68 @@
using System;
using System.Text;
using System.Windows.Forms;
using mRemoteNG.App;
namespace mRemoteNG.UI.Forms
{
public partial class UnhandledExceptionWindow : Form
{
private readonly bool _isFatal;
public UnhandledExceptionWindow()
: this(null, false)
{
}
public UnhandledExceptionWindow(Exception exception, bool isFatal)
{
_isFatal = isFatal;
InitializeComponent();
SetLanguage();
if (exception == null)
return;
textBoxExceptionMessage.Text = exception.Message;
textBoxStackTrace.Text = exception.StackTrace;
}
private void SetLanguage()
{
Text = Language.mRemoteNGUnhandledException;
labelExceptionCaught.Text = Language.UnhandledExceptionOccured;
labelExceptionIsFatalHeader.Text = _isFatal
? Language.ExceptionForcesmRemoteNGToClose
: string.Empty;
labelExceptionMessageHeader.Text = Language.ExceptionMessage;
labelStackTraceHeader.Text = Language.StackTrace;
buttonCopyAll.Text = Language.strMenuNotificationsCopyAll;
buttonClose.Text = _isFatal
? Language.strMenuExit
: Language.strButtonClose;
}
private void buttonCopyAll_Click(object sender, EventArgs e)
{
var text = new StringBuilder()
.AppendLine(labelExceptionMessageHeader.Text)
.AppendLine("\"" + textBoxExceptionMessage.Text + "\"")
.AppendLine()
.AppendLine(labelStackTraceHeader.Text)
.AppendLine(textBoxStackTrace.Text)
.ToString();
Clipboard.SetText(text);
}
private void buttonClose_Click(object sender, EventArgs e)
{
if (_isFatal)
Shutdown.Quit();
Close();
}
}
}

View File

@@ -0,0 +1,120 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

View File

@@ -652,6 +652,12 @@
<Compile Include="UI\Forms\TextBox.cs">
<SubType>Component</SubType>
</Compile>
<Compile Include="UI\Forms\UnhandledExceptionWindow.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="UI\Forms\UnhandledExceptionWindow.Designer.cs">
<DependentUpon>UnhandledExceptionWindow.cs</DependentUpon>
</Compile>
<Compile Include="UI\Menu\HelpMenu.cs">
<SubType>Component</SubType>
</Compile>
@@ -895,6 +901,9 @@
<DependentUpon>ReconnectGroup.cs</DependentUpon>
<SubType>Designer</SubType>
</EmbeddedResource>
<EmbeddedResource Include="UI\Forms\UnhandledExceptionWindow.resx">
<DependentUpon>UnhandledExceptionWindow.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="UI\TaskDialog\frmTaskDialog.resx">
<DependentUpon>frmTaskDialog.cs</DependentUpon>
</EmbeddedResource>