frmExceptionError.cs 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9. namespace LYFZ.ComponentLibrary
  10. {
  11. public partial class frmExceptionError : Form
  12. {
  13. public frmExceptionError()
  14. {
  15. InitializeComponent();
  16. this.Shown += frmExceptionError_Shown;
  17. }
  18. string _VersionNumber = "";
  19. public string VersionNumber
  20. {
  21. get { return _VersionNumber; }
  22. set { _VersionNumber = value; }
  23. }
  24. public void SetErrorInfo()
  25. {
  26. int errCode = System.Runtime.InteropServices.Marshal.GetLastWin32Error();//获取错误码。
  27. string ErrorMessages = LYFZ.WinAPI.Win32.GetSysErrMsg(errCode);
  28. this.lbErrorMsg.Text = string.Format("程序在运行时发生错误,建议您关闭后重试,也可以把错误报告给开发工程师以便修复此问题!\r\n出现应用程序未处理的异常:" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + VersionNumber + "\r\n异常类型:{0}\r\n异常消息:{1}", errorTypeName, errorMessage);
  29. this.txtErrorInfo.Text = this.lbErrorMsg.Text + "\r\nLastWin32Error代码 " + errCode.ToString() + ":"+errorMessage+"\r\n" + errorStackTrace;
  30. }
  31. void frmExceptionError_Shown(object sender, EventArgs e)
  32. {
  33. SetErrorInfo();
  34. }
  35. string errorTypeName = "";
  36. /// <summary>
  37. /// 异常类型
  38. /// </summary>
  39. public string ErrorTypeName
  40. {
  41. get { return errorTypeName; }
  42. set { errorTypeName = value; }
  43. }
  44. string errorMessage = "";
  45. /// <summary>
  46. /// 异常消息
  47. /// </summary>
  48. public string ErrorMessage
  49. {
  50. get { return errorMessage; }
  51. set { errorMessage = value; }
  52. }
  53. string errorStackTrace = "";
  54. /// <summary>
  55. /// 堆栈信息
  56. /// </summary>
  57. public string ErrorStackTrace
  58. {
  59. get { return errorStackTrace; }
  60. set { errorStackTrace = value; }
  61. }
  62. private void buttonClose_Click(object sender, EventArgs e)
  63. {
  64. this.Close();
  65. }
  66. }
  67. }