..在VS debug 模式下會“無法捕獲” System.NullReferenceException。。。。。。但是在release 或者外部運行是能捕獲的。
test code :
Form2 f = null; try { f.Dispose(); } catch (NullReferenceException ex) { MessageBox.Show("get:"+ex.Message); }
其實只是VS 在調試模式故意彈出的斷點,可以在調試時候出現的Exception Settings窗口設置里取消勾選“System.NullReferenceException”(在debug的時候回出來這個Exception Settings窗口,然后查找"NullReferenceException“”)