1 °³¿ä
2 ¿¹¿Ü ¹ß»ý½Ã ÄݽºÅà ÆÄÀÏ¿¡´Ù ±â·ÏÇϱâ
WinForms ¾ÖÇø®ÄÉÀ̼ÇÀÇ °æ¿ì¿¡´Â Application.ThreadException Çڵ鷯¸¦ ÁöÁ¤ÇØÁÖ¸é µÇ°í, ÄÜ¼Ö ¾ÖÇø®ÄÉÀ̼ÇÀÇ °æ¿ì¿¡´Â AppDomain.CurrentDomain.UnhandledException Çڵ鷯¸± ÁöÁ¤ÇØÁÖ¸é µÈ´Ù.
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Text;
using System.Windows.Forms;
using System.Threading;
namespace YourNameSpace
{
class DebugHelper
{
public static void InstallExceptionHandler()
{
Application.ThreadException +=
new ThreadExceptionEventHandler(ThreadExceptionHandler);
AppDomain.CurrentDomain.UnhandledException +=
new UnhandledExceptionEventHandler(UnhandledExceptionHandler);
}
private static void ThreadExceptionHandler(object sender, ThreadExceptionEventArgs args)
{
HandleException((Exception)args.Exception);
}
private static void UnhandledExceptionHandler(object sender, UnhandledExceptionEventArgs args)
{
HandleException((Exception)args.ExceptionObject);
}
private static void HandleException(Exception e)
{
// unmanaged exceptionÀÎ °æ¿ì e°¡ null·Î ³Ñ¾î¿Â´Ù.
// ó¸®ÇØ¾ß Çϴµ¥... ±ÍÂú´Ù.
StreamWriter file = new System.IO.StreamWriter(
Application.StartupPath + "\\error.log",
false,
System.Text.Encoding.Default
);
file.WriteLine(e.StackTrace);
file.Close();
MessageBox.Show(
"A fatal problem has occurred.\n" + e.Message + "\nin: " + e.GetType(),
"Program Stopped",
MessageBoxButtons.OK,
MessageBoxIcon.Stop,
MessageBoxDefaultButton.Button1);
Trace.Close();
Process.GetCurrentProcess().Kill();
}
}
} ÇÁ·Î±×·¥ ÃʱâÈ ÇÏ´Â ºÎºÐ ¾îµò°¡¿¡¼ InstallExceptionHandler È£ÃâÇØ ÁØ´Ù.
DebugHelper.InstallExceptionHandler();
3 ¸µÅ©
SeriousMoin v1 (koMoinMoin 1.0a4 Modified)