⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 subject_42897.htm

📁 一些关于vc的问答
💻 HTM
字号:
<p>
序号:42897 发表者:qihua 发表日期:2003-06-06 17:30:30
<br>主题:关于未知异常的捕获和信息显示,请高手一定要指点,谢谢了!
<br>内容:比如:<BR>我在某个函数中有一句:throw(“It's a Exception !”);<BR>然后,应用程序又调用了这个函数,并且没有用try块包含;<BR>然后,系统捕获到了这个异常,并将这个异常作为未知异常交给应用程序的缺省异常处理函数。<BR><BR>请问,我如何在应用程序的缺省处理函数中得到上面throw(“”)中的信息?<BR><BR>如果能够得到的话,我就可以在缺省异常处理函数中写日志了,再也不用为每个类提供日志接口,简化开发复杂度。
<br><a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p>
<hr size=1>
<blockquote><p>
回复者:Neil Gan 回复日期:2003-06-07 05:55:31
<br>内容:SetUnhandledExceptionFilter
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
回复者:qihua 回复日期:2003-06-07 08:52:46
<br>内容:首先谢谢你的回答。<BR>但是在捕获到未知异常是如何得到throw()中的内容呢?这是关键。
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
回复者:Neil Gan 回复日期:2003-06-07 10:02:43
<br>内容:GetExceptionInfomation<BR><BR>But, this function can NOT tell you what exactly was throwed. It can only tell you:<BR><BR>The exception code //for all throwed exception, it is the same. but there are other Windows exception code<BR>Exception Address<BR>The CPU status when exception occured<BR>And other information<BR><BR>Read MSDN and Jeffrey Richter's book for more information
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
回复者:qihua 回复日期:2003-06-07 10:58:43
<br>内容:Jeffrey Richter 的书我也研究过,但是就是得不到具体异常信息,光是靠那些16进制的地址和CPU信息,很难定位到程序的问题所在。<BR><BR><BR>真的就没有其他办法了吗?
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
回复者:Neil Gan 回复日期:2003-06-07 11:09:38
<br>内容:Because in VC, C++ exception is implemented in term of SEH, so, I guess "throw" actually calls RaiseException to throw it.<BR><BR>in EXCEPTION_RECORD, there is a field: ExceptionInformation. I guess you can find what was throwed in this field. But because the detail of this field is not documented, so you can only use it on your risk, that is, it is possible that the format of the field will be changed and not compatible with your program any more.
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
回复者:qihua 回复日期:2003-06-07 11:43:06
<br>内容:<BR>你上面的方法我以前尝试过,就是不行,<BR><BR>不过刚才看了一下你的资料,知道你是一个高手,如果连你都认为无法得到,那<BR>我真是要放弃了。<BR><BR>另外,如果方便的话问你一个题外话,您现在在什么单位工作?我是ZTE的,今天在加班,不妨交个朋友,好吗?<BR>
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
<font color=red>答案被接受</font><br>回复者:Neil Gan 回复日期:2003-06-07 12:33:45
<br>内容:Just now I tried it. you CAN get what was throwed from ExceptionInformation:<BR><BR>#include &lt;windows.h&gt;<BR><BR>long ExceptionFilter(EXCEPTION_POINTERS *psExceptionInfo)<BR>{<BR>&nbsp;&nbsp;&nbsp;&nbsp;char *pc=*(char**)(psExceptionInfo-&gt;ExceptionRecord-&gt;ExceptionInformation[1]);<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;return EXCEPTION_EXECUTE_HANDLER;<BR>}<BR><BR>int WINAPI WinMain (HINSTANCE,HINSTANCE,PSTR,int)<BR>{<BR>&nbsp;&nbsp;&nbsp;&nbsp;char *pc="The Quick Brown Fox Jumps Over A Lazy Dog.";<BR>&nbsp;&nbsp;&nbsp;&nbsp;__try<BR>&nbsp;&nbsp;&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;throw(pc);<BR>&nbsp;&nbsp;&nbsp;&nbsp;}__except(ExceptionFilter(GetExceptionInformation()))<BR>&nbsp;&nbsp;&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;&nbsp;}<BR>&nbsp;&nbsp;&nbsp;&nbsp;return 0;<BR>}<BR><BR>I set a breakpoint in function ExceptionFilter, the content of pc is "The Quick..."<BR><BR>For other kind of throw, you can try it yourself.<BR><BR>All sincere members in VCHelp are my friends.<BR>
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
回复者:Neil Gan 回复日期:2003-06-07 12:35:52
<br>内容:I wrote this test program and did assembler level trace for "throw", then I found the answer. perhaps you should do it yourself for other kind of throws.
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
回复者:qihua 回复日期:2003-06-07 12:37:10
<br>内容:thank you!
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
回复者:Neil Gan 回复日期:2003-06-07 12:45:07
<br>内容:you are welcome.<BR><BR>Actually, I never met this problem. It is your question that made me to do the research. Solving your problem helps me a lot too.<BR><BR>So, I also need to say thanks to you.
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -