frmExceptionError.cs 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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("出现异常:" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + VersionNumber + "\r\n类型:{0}\r\n消息:{1}", errorTypeName, errorMessage);
  29. string errorStr = string.Format("程序在运行时发生错误,建议您关闭后重试,也可以把错误报告给开发工程师以便修复此问题!\r\n出现应用程序未处理的异常:" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + VersionNumber + "\r\n异常类型:{0}\r\n异常消息:{1}", errorTypeName, errorMessage);
  30. this.txtErrorInfo.Text = errorStr + "\r\nLastWin32Error代码 " + errCode.ToString() + ":" + errorMessage + "\r\n" + errorStackTrace;
  31. }
  32. void frmExceptionError_Shown(object sender, EventArgs e)
  33. {
  34. SetErrorInfo();
  35. }
  36. string errorTypeName = "";
  37. /// <summary>
  38. /// 异常类型
  39. /// </summary>
  40. public string ErrorTypeName
  41. {
  42. get { return errorTypeName; }
  43. set { errorTypeName = value; }
  44. }
  45. string errorMessage = "";
  46. /// <summary>
  47. /// 异常消息
  48. /// </summary>
  49. public string ErrorMessage
  50. {
  51. get { return errorMessage; }
  52. set { errorMessage = value; }
  53. }
  54. string errorStackTrace = "";
  55. /// <summary>
  56. /// 堆栈信息
  57. /// </summary>
  58. public string ErrorStackTrace
  59. {
  60. get { return errorStackTrace; }
  61. set { errorStackTrace = value; }
  62. }
  63. private void buttonClose_Click(object sender, EventArgs e)
  64. {
  65. this.Close();
  66. }
  67. }
  68. }