ThreadExceptionDialog.cs 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. //
  2. // System.Windows.Forms.ThreadExceptionDialog.cs
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining
  5. // a copy of this software and associated documentation files (the
  6. // "Software"), to deal in the Software without restriction, including
  7. // without limitation the rights to use, copy, modify, merge, publish,
  8. // distribute, sublicense, and/or sell copies of the Software, and to
  9. // permit persons to whom the Software is furnished to do so, subject to
  10. // the following conditions:
  11. //
  12. // The above copyright notice and this permission notice shall be
  13. // included in all copies or substantial portions of the Software.
  14. //
  15. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  16. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  17. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  18. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  19. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  20. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  21. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  22. //
  23. // Autors:
  24. // Marek Safar [email protected]
  25. //
  26. // Copyright (C) Novell Inc., 2004
  27. // COMPLETE - BUT DISABLED TEXTBOX
  28. using System;
  29. using System.Text;
  30. using System.Reflection;
  31. namespace System.Windows.Forms
  32. {
  33. public class ThreadExceptionDialog: Form
  34. {
  35. Exception e;
  36. bool details;
  37. private System.Windows.Forms.Button buttonIgnore;
  38. private System.Windows.Forms.Button buttonAbort;
  39. private System.Windows.Forms.Button buttonDetails;
  40. private System.Windows.Forms.Label labelException;
  41. private System.Windows.Forms.Label label1;
  42. #if TEXTBOX
  43. private System.Windows.Forms.TextBox textBoxDetails;
  44. #endif
  45. private System.Windows.Forms.Label helpText;
  46. private void InitializeComponent()
  47. {
  48. this.helpText = new System.Windows.Forms.Label();
  49. this.buttonAbort = new System.Windows.Forms.Button();
  50. this.buttonIgnore = new System.Windows.Forms.Button();
  51. this.buttonDetails = new System.Windows.Forms.Button();
  52. this.labelException = new System.Windows.Forms.Label();
  53. #if TEXTBOX
  54. this.textBoxDetails = new System.Windows.Forms.TextBox();
  55. #endif
  56. this.label1 = new System.Windows.Forms.Label();
  57. this.SuspendLayout();
  58. //
  59. // helpText
  60. //
  61. this.helpText.Location = new System.Drawing.Point(60, 8);
  62. this.helpText.Name = "helpText";
  63. this.helpText.Size = new System.Drawing.Size(356, 40);
  64. this.helpText.TabIndex = 0;
  65. this.helpText.Text = "An unhandled exception has occurred in you application. If you click Ignore the a" +
  66. "pplication will ignore this error and attempt to continue. If you click Abort, t" +
  67. "he application will quit immediately.";
  68. //
  69. // buttonAbort
  70. //
  71. this.buttonAbort.DialogResult = System.Windows.Forms.DialogResult.Abort;
  72. this.buttonAbort.Location = new System.Drawing.Point(332, 112);
  73. this.buttonAbort.Name = "buttonAbort";
  74. this.buttonAbort.Size = new System.Drawing.Size(85, 23);
  75. this.buttonAbort.TabIndex = 4;
  76. this.buttonAbort.Text = "&Abort";
  77. this.buttonAbort.Click += new System.EventHandler(this.buttonAbort_Click);
  78. //
  79. // buttonIgnore
  80. //
  81. this.buttonIgnore.DialogResult = System.Windows.Forms.DialogResult.Ignore;
  82. this.buttonIgnore.Location = new System.Drawing.Point(236, 112);
  83. this.buttonIgnore.Name = "buttonIgnore";
  84. this.buttonIgnore.Size = new System.Drawing.Size(85, 23);
  85. this.buttonIgnore.TabIndex = 3;
  86. this.buttonIgnore.Text = "&Ignore";
  87. //
  88. // buttonDetails
  89. //
  90. this.buttonDetails.Location = new System.Drawing.Point(140, 112);
  91. this.buttonDetails.Name = "buttonDetails";
  92. this.buttonDetails.Size = new System.Drawing.Size(85, 23);
  93. this.buttonDetails.TabIndex = 2;
  94. this.buttonDetails.Text = "Show &Details";
  95. this.buttonDetails.Click += new System.EventHandler(this.buttonDetails_Click);
  96. //
  97. // labelException
  98. //
  99. this.labelException.Location = new System.Drawing.Point(60, 64);
  100. this.labelException.Name = "labelException";
  101. this.labelException.Size = new System.Drawing.Size(356, 32);
  102. this.labelException.TabIndex = 1;
  103. //
  104. // textBoxDetails
  105. //
  106. #if TEXTBOX
  107. this.textBoxDetails.Location = new System.Drawing.Point(8, 168);
  108. this.textBoxDetails.Multiline = true;
  109. this.textBoxDetails.Name = "textBoxDetails";
  110. this.textBoxDetails.ReadOnly = true;
  111. this.textBoxDetails.ScrollBars = System.Windows.Forms.ScrollBars.Both;
  112. this.textBoxDetails.Size = new System.Drawing.Size(408, 196);
  113. this.textBoxDetails.TabIndex = 5;
  114. this.textBoxDetails.TabStop = false;
  115. this.textBoxDetails.Text = "";
  116. this.textBoxDetails.WordWrap = false;
  117. #endif
  118. //
  119. // label1
  120. //
  121. this.label1.Location = new System.Drawing.Point(8, 148);
  122. this.label1.Name = "label1";
  123. this.label1.Size = new System.Drawing.Size(100, 16);
  124. this.label1.TabIndex = 0;
  125. this.label1.Text = "Exception details";
  126. //
  127. // ThreadExceptionDialog
  128. //
  129. this.AcceptButton = this.buttonIgnore;
  130. this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
  131. this.CancelButton = this.buttonAbort;
  132. this.ClientSize = new System.Drawing.Size(428, 374);
  133. this.Controls.Add(this.label1);
  134. #if TEXTBOX
  135. this.Controls.Add(this.textBoxDetails);
  136. #endif
  137. this.Controls.Add(this.labelException);
  138. this.Controls.Add(this.buttonDetails);
  139. this.Controls.Add(this.buttonIgnore);
  140. this.Controls.Add(this.buttonAbort);
  141. this.Controls.Add(this.helpText);
  142. this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
  143. this.MaximizeBox = false;
  144. this.MinimizeBox = false;
  145. this.Name = "ThreadExceptionDialog";
  146. this.ShowInTaskbar = false;
  147. this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
  148. this.TopMost = true;
  149. this.ResumeLayout(false);
  150. }
  151. public ThreadExceptionDialog (Exception e)
  152. {
  153. this.e = e;
  154. InitializeComponent ();
  155. this.labelException.Text = e.Message;
  156. if (Form.ActiveForm != null)
  157. this.Text = Form.ActiveForm.Text;
  158. else
  159. this.Text = "Mono";
  160. this.buttonAbort.Enabled = Application.AllowQuit;
  161. RefreshDetails ();
  162. FillExceptionDetails ();
  163. }
  164. void buttonDetails_Click(object sender, System.EventArgs e)
  165. {
  166. details = !details;
  167. RefreshDetails ();
  168. }
  169. void FillExceptionDetails ()
  170. {
  171. StringBuilder sb = new StringBuilder ();
  172. sb.Append (e.ToString ());
  173. sb.Append (Environment.NewLine + Environment.NewLine);
  174. sb.Append ("Loaded assemblies:" + Environment.NewLine + Environment.NewLine);
  175. foreach (Assembly a in AppDomain.CurrentDomain.GetAssemblies ()) {
  176. AssemblyName an = a.GetName ();
  177. sb.AppendFormat ("Name:\t{0}" + Environment.NewLine, an.Name);
  178. sb.AppendFormat ("Version:\t{0}" + Environment.NewLine, an.Version);
  179. sb.AppendFormat ("Location:\t{0}" + Environment.NewLine, an.CodeBase);
  180. sb.Append (Environment.NewLine);
  181. }
  182. #if TEXTBOX
  183. textBoxDetails.Text = sb.ToString ();
  184. #endif
  185. }
  186. void RefreshDetails ()
  187. {
  188. if (details) {
  189. buttonDetails.Text = "Hide &Details";
  190. Height = 410;
  191. return;
  192. }
  193. buttonDetails.Text = "Show &Details";
  194. Height = 180;
  195. }
  196. void buttonAbort_Click(object sender, System.EventArgs e)
  197. {
  198. Application.Exit ();
  199. }
  200. }
  201. }