C#_WinForm에서 처리되지 않은 예외 캡처
2464 단어 WinForm
static class Program
{
/// <summary>
/// 。
/// </summary>
[STAThread]
static void Main()
{
try
{
//
Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);
// UI
Application.ThreadException += new System.Threading.ThreadExceptionEventHandler(Application_ThreadException);
// UI
AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new frmlogin());
}
catch(Exception ex)
{
frmBug f = new frmBug(ex.Message);//
f.ShowDialog();
}
}
static void Application_ThreadException(object sender, System.Threading.ThreadExceptionEventArgs e)
{
string str = "";
Exception error = e.Exception as Exception;
if (error != null)
{
str =string.Format("
:{0}
:{1}
:{2}
",
error.GetType().Name, error.Message, error.StackTrace);
}
else
{
str =string.Format(" :{0}", e);
}
frmBug f = new frmBug(str);//
f.ShowDialog();
}
static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
{
string str = "";
Exception error = e.ExceptionObject as Exception;
if (error != null)
{
str =string.Format("Application UnhandledException:{0};
:{1}", error.Message, error.StackTrace);
}
else
{
str =string.Format("Application UnhandledError:{0}", e);
}
frmBug f = new frmBug(str);//
f.ShowDialog();
}
}
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
C# Excel 템플릿 내보내기(Word 등)프로젝트에서 Excel, Word, pdf 등 템플릿 내보내기를 자주 사용해야 합니다. 다음은 자신이 정리한 간단한 버전의 템플릿 내보내기입니다. 복잡한 내보내기와 유사합니다. 조금만 수정하면 됩니다.다음 내보내기 ...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.