首页 > 学院 > 开发设计 > 正文

.Net 4.0里面try/catch没有抓住的exception

2019-11-17 03:19:04
字体:
来源:转载
供稿:网友
.Net 4.0里面try/catch没有抓住的exception

像try{…}catch(Exception){…}这样的代码,我们知道是抓不住Non CLS Compliant的Exception的。但是就一定能抓住CLS Compliant的Exception吗?事实发现从.net 4.0开始未必。

QA报告了一个问题,说点了一个按钮之后系统弹了一个框说Fatal application Error,提示重启。QA抓了一下log和dump就重启继续测了。这个问题之前从来没发生过,之后也重现不出来,但就发生了那么一次,而且是很normal的workflow。这种对话框是我们系统处理AppDomain.CurrentDomain.UnhandledException的标准错误框,这种问题我们的日志里面会有详细的Exception的call stack,一般来说应该在某个地方加条件判断或者try/catch一下,轻松搞定Smile

看了一下日志,全是底层的函数,没见我们的代码。

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没抓住! 为什么?为什么?! Sad smile

只能看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

<

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表