获取有关在catch块中抛出c ++异常的信息? [英] Getting information about where c++ exceptions are thrown inside of catch block?

查看:255
本文介绍了获取有关在catch块中抛出c ++异常的信息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个c ++应用程序在try块中包装大部分代码。当我捕获异常,我可以返回用户到一个稳定的状态,这是很好的。但我不再收到故障转储。我真的想搞清楚在代码中异常发生在哪里,所以我可以记录它,并解决它。

I've got a c++ app that wraps large parts of code in try blocks. When I catch exceptions I can return the user to a stable state, which is nice. But I'm not longer receiving crash dumps. I'd really like to figure out where in the code the exception is taking place, so I can log it and fix it.

能够获得转储而不停止应用程序将是理想的,但我不能确定是可能的。

Being able to get a dump without halting the application would be ideal, but I'm not sure that's possible.

有一些方法,我可以弄清楚在catch块中抛出异常的地方吗?如果它是有用的,我使用本机msvc ++在windows xp和更高。我的计划是简单地记录崩溃到各种用户的机器上的文件,然后一旦他们达到一定的大小上传崩溃日志。

Is there some way I can figure out where the exception was thrown from within the catch block? If it's useful, I'm using native msvc++ on windows xp and higher. My plan is to simply log the crashes to a file on the various users' machines, and then upload the crashlogs once they get to a certain size.

推荐答案

使用SEH(结构化异常处理)是可能的。关键是MSVC通过SEH实现了C ++异常。另一方面,纯SEH更强大,更灵活。

This is possible with using SEH (structured exception handling). The point is that MSVC implements C++ exceptions via SEH. On the other hand the pure SEH is much more powerful and flexible.

这是你应该做的。而不是像下面这样使用纯C ++ try / catch块:

That's what you should do. Instead of using pure C++ try/catch blocks like this:

try
{
    DoSomething();
} catch(MyExc& exc)
{
    // process the exception
}

您应该使用SEH块封装内部代码块 DoSomething

You should wrap the inner code block DoSomething with the SEH block:

void DoSomething()
{
    __try {
        DoSomethingInner();
    }
    __except (DumpExc(GetExceptionInformation()), EXCEPTION_CONTINUE_SEARCH) {
        // never get there
    }
}

void DumpEx(EXCEPTION_POINTERS* pExc)
{
    // Call MiniDumpWriteDump to produce the needed dump file
}

也就是说,在C ++ try / catch块中,我们放置另一个原始SEH块,它只转储所有异常而不捕获它们。

That is, inside the C++ try/catch block we place another raw SEH block, which only dumps all the exceptions without catching them.

请参阅

See here for an example of using MiniDumpWriteDump.

这篇关于获取有关在catch块中抛出c ++异常的信息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆