像try{…}catch(Exception){…}這樣的代碼,我們知道是抓不住Non CLS Compliant的Exception的。但是就一定能抓住CLS Compliant的Exception嗎?事實發(fā)現(xiàn)從.net 4.0開始未必。
QA報告了一個問題,說點了一個按鈕之后系統(tǒng)彈了一個框說Fatal application Error,提示重啟。QA抓了一下log和dump就重啟繼續(xù)測了。這個問題之前從來沒發(fā)生過,之后也重現(xiàn)不出來,但就發(fā)生了那么一次,而且是很normal的workflow。這種對話框是我們系統(tǒng)處理AppDomain.CurrentDomain.UnhandledException的標準錯誤框,這種問題我們的日志里面會有詳細的Exception的call stack,一般來說應該在某個地方加條件判斷或者try/catch一下,輕松搞定
看了一下日志,全是底層的函數(shù),沒見我們的代碼。
| ExceptionName: System.Runtime.InteropServices.COMException ExceptionString: System.Runtime.InteropServices.COMException (0x80040064): Invalid FORMATETC structure (Exception from HRESULT: 0x80040064 (DV_E_FORMATETC)) at System.Runtime.InteropServices.Marshal.ThrowExceptionForHRInternal(Int32 errorCode, IntPtr errorInfo) at System.Windows.Forms.DataObject.System.Runtime.InteropServices.ComTypes.IDataObject.GetDataHere(FORMATETC& formatetc, STGMEDIUM& medium) at System.Windows.Forms.DataObject.System.Runtime.InteropServices.ComTypes.IDataObject.GetData(FORMATETC& formatetc, STGMEDIUM& medium) at System.Runtime.InteropServices.Marshal.ThrowExceptionForHRInternal(Int32 errorCode, IntPtr errorInfo) at System.Windows.Forms.DataObject.System.Runtime.InteropServices.ComTypes.IDataObject.GetDataHere(FORMATETC& formatetc, STGMEDIUM& medium) at System.Windows.Forms.DataObject.System.Runtime.InteropServices.ComTypes.IDataObject.GetData(FORMATETC& formatetc, STGMEDIUM& medium) at System.Runtime.InteropServices.Marshal.ThrowExceptionForHRInternal(Int32 errorCode, IntPtr errorInfo) at System.Windows.Forms.DataObject.System.Runtime.InteropServices.ComTypes.IDataObject.GetDataHere(FORMATETC& formatetc, STGMEDIUM& medium) at System.Runtime.InteropServices.Marshal.ThrowExceptionForHRInternal(Int32 errorCode, IntPtr errorInfo) at System.Windows.Forms.DataObject.System.Runtime.InteropServices.ComTypes.IDataObject.GetData(FORMATETC& formatetc, STGMEDIUM& medium) InnerException: MachineName: DR2014227932 StackTrace: at System.Runtime.InteropServices.Marshal.ThrowExceptionForHRInternal(Int32 errorCode, IntPtr errorInfo) at System.Windows.Forms.DataObject.System.Runtime.InteropServices.ComTypes.IDataObject.GetDataHere(FORMATETC& formatetc, STGMEDIUM& medium) at System.Windows.Forms.DataObject.System.Runtime.InteropServices.ComTypes.IDataObject.GetData(FORMATETC& formatetc, STGMEDIUM& medium) at System.Runtime.InteropServices.Marshal.ThrowExceptionForHRInternal(Int32 errorCode, IntPtr errorInfo) at System.Windows.Forms.DataObject.System.Runtime.InteropServices.ComTypes.IDataObject.GetDataHere(FORMATETC& formatetc, STGMEDIUM& medium) at System.Windows.Forms.DataObject.System.Runtime.InteropServices.ComTypes.IDataObject.GetData(FORMATETC& formatetc, STGMEDIUM& medium) at System.Runtime.InteropServices.Marshal.ThrowExceptionForHRInternal(Int32 errorCode, IntPtr errorInfo) at System.Windows.Forms.DataObject.System.Runtime.InteropServices.ComTypes.IDataObject.GetDataHere(FORMATETC& formatetc, STGMEDIUM& medium) at System.Runtime.InteropServices.Marshal.ThrowExceptionForHRInternal(Int32 errorCode, IntPtr errorInfo) at System.Windows.Forms.DataObject.System.Runtime.InteropServices.ComTypes.IDataObject.GetData(FORMATETC& formatetc, STGMEDIUM& medium) |
然后又看了一下Button Click代碼,類似是這樣的
| try { Clipboard.GetDataObject(); … Clipboard.SetDataObject() … } catch (Exception ex) { //log and ignore } |
這個… Exception沒抓住! 為什么?為什么?! ![]()
只能看dump了
#看看主線程在干嘛
| 0:000> !clrstack OS Thread Id: 0xe7c (0) Child SP IP Call Site 000000000021d6a8 00000000775a186a [NDirectMethodFrameStandalone: 000000000021d6a8] System.Windows.Forms.UnsafeNativeMethods.OleFlushClipboard() 000000000021d660 000007fef1a7227f System.Windows.Forms.Clipboard.SetDataObject(System.Object, Boolean, Int32, Int32) 000000000021d7a0 000007ff029023f9 TheControls.CCDeliveryStatusDisplayControl.InsertDestinationIcon(CCOutputRow) 000000000021d810 000007ff029020bf TheControls.CCDeliveryStatusDisplayControl.InsertDestinationIcon(CCOutputRow) 000000000021d960 000007ff029013b0 TheControls.CCDeliveryStatusDisplayControl.WriteOutputRows(CCOutputRow[]) 000000000021dac0 000007ff02717b5a TheSystem.CCMultiFormatConfiguration2.ShowDeliveryStatusPanel(Boolean) 000000000021db00 000007ff028fc1ea TheSystem.CCMultiFormatConfiguration2.buttonPRint_Click(System.Object, System.EventArgs) 000000000021db50 000007ff01fbab9e TheControls.CCButton.OnClick(System.EventArgs) …<cut to save space>… |
嗯,QA確實是點了一個按鈕,然后當前call stack也看不出更多信息。(~* e!clrstack也沒啥有用信息)
#看看unmanaged call stack吧
| 0:000> kb RetAddr : Args to Child : Call Site 000007fe`fdd11430 : 0074006c`00750061 00650078`0065002e 00000000`00000000 00000000`00000000 : ntdll!NtWaitForMultipleObjects+0xa 00000000`76e92ce3 : 00000000`0021bf80 00000000`0021bf70 00000000`00000000 00000000`00000000 : KERNELBASE!GetCurrentProcess+0x40 00000000`76f09105 : 00000000`055a0000 00000000`0021c1f0 00000000`00000000 00000000`0021d470 : kernel32!WaitForMultipleObjectsExImplementation+0xb3 00000000`76f09287 : 00000000`00000000 01000000`00000080 00000000`00001920 00000000`00000000 : kernel32!WerpReportFaultInternal+0x215 00000000`76f092df : 00000000`0021c1f0 00000000`00000001 00000000`00000000 00000000`000d6910 : kernel32!WerpReportFault+0x77 00000000`76f094fc : 00000000`00000000 00000000`00000001 00000000`00000001 000007fe`ff095d58 : kernel32!BasepReportFault+0x1f 00000000`776368df : 00000000`0021c1f0 000007fe`00000006 00000000`00000000 00000000`00000001 : kernel32!UnhandledExceptionFilter+0x1fc 00000000`775a1163 : 00000000`0021cef0 00000000`0021ca00 00000000`00220000 00000000`775a11f5 : ntdll!RtlNewInstanceSecurityObject+0x11f 00000000`77579d2d : 00000000`00220000 00000000`0021c3a8 00000000`0021c330 000007fe`ff146454 : ntdll!KiUserApcDispatcher+0x93 00000000`775691cf : 00000000`00220000 00000000`772d6388 00000000`00012f00 00000000`000bd960 : ntdll!RtlDecodePointer+0xad 00000000`775a1248 : 00000000`0021cef0 00000000`0021ca00 00000000`00000000 000007fe`00000000 : ntdll!RtlUnwindEx+0xbbf < 學習交流
熱門圖片
猜你喜歡的新聞
新聞熱點 2019-10-23 09:17:05
2019-10-21 09:20:02
2019-10-21 09:00:12
2019-09-26 08:57:12
2019-09-25 08:46:36
2019-09-25 08:15:43
疑難解答 |