?? 未處理異常的策略.txt
字號:
1.發生未處理異常是CLR行為控制
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\.NETFramework的DbgJITDebugLaunchSetting
0 顯示對話框詢問用戶是否要調試。
1 不向用戶顯示任何對話框,調用MgdUEPolicy回調方法。
2 不向用戶顯示任何對話框,CLR啟動調試器并將其連接到應用程序上。
using System;
using System.Diagnostics;
using System.Windows.Forms;
namespace TestExce
{
/// <summary>
/// 未處理異常的策略
/// </summary>
class Class1
{
[STAThread]
static void Main(string[] args)
{
AppDomain.CurrentDomain.UnhandledException+=new UnhandledExceptionEventHandler(MgdUEPolicy);
try
{
Object o=null;
o.GetType();
}
finally
{
Console.WriteLine("In finally");
}
}
static void MgdUEPolicy(Object sender,UnhandledExceptionEventArgs e)
{
String info;
Exception ex=e.ExceptionObject as Exception;
if(ex!=null)
{
//CLS兼容異常
info=ex.ToString();
}
else
{
//CLS不兼容異常
info=String.Format("Non-CLS-Compliant exception:Type={0},String={1}",e.ExceptionObject.GetType(),e.ExceptionObject.ToString());
}
#if DEBUG
if(!e.IsTerminating)
{
Debugger.Launch();
}
else
{
Debugger.Launch();
}
#else
if(!e.IsTerminating)
{
}
else
{
String msg=String.Format("{0} has encountered aproblem and "+
"need to close.we are sorry for the inconvenience.\n\n"+
"Please tell{1} about this problem.\n"+
"We have created an error report that you can send to"+
"help us imporove{0}."+
"We will treat this report as confidential and anonymuse.\n\n"+
"Would you like to send the report?","(AppName)","(CompanyName)");
if(MessageBox.Show(msg,"(AppName)",MessageBoxButtons.YesNo)==DialogResult.Yes)
{
MessageBox.Show(info,"Error Report");
}
}
#endif
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -