C++;:如何解决在未知点引起的首次机会异常? 我正在处理的C++项目在抛出第一个机会异常时终止。当我第一次尝试访问包含单个键值对的map时,在Visual Studio 2008的调试模式下会出现这种情况。代码在逻辑上没有什么错误

C++;:如何解决在未知点引起的首次机会异常? 我正在处理的C++项目在抛出第一个机会异常时终止。当我第一次尝试访问包含单个键值对的map时,在Visual Studio 2008的调试模式下会出现这种情况。代码在逻辑上没有什么错误,c++,visual-studio-2008,first-chance-exception,C++,Visual Studio 2008,First Chance Exception,我已经阅读了第一次机会的例外情况,并理解它们可能并不总是有问题的。尽管如此,我还是尝试打破所有这些异常,正如预期的那样,发现生成了几个不会引起问题的异常 我正在处理的类非常大,包含许多自定义内存分配。我猜测,不知何故,其中一个问题是由这些因素引起的。然而,我花了几个小时试图找到一种方法来确定出了什么问题,但一直无法做到这一点 下面列出了第一次机会异常输出。这不是很有帮助 First-chance exception at 0x762cd09c in theapp.exe: 0xC0000005:

我已经阅读了第一次机会的例外情况,并理解它们可能并不总是有问题的。尽管如此,我还是尝试打破所有这些异常,正如预期的那样,发现生成了几个不会引起问题的异常

我正在处理的类非常大,包含许多自定义内存分配。我猜测,不知何故,其中一个问题是由这些因素引起的。然而,我花了几个小时试图找到一种方法来确定出了什么问题,但一直无法做到这一点

下面列出了第一次机会异常输出。这不是很有帮助

First-chance exception at 0x762cd09c in theapp.exe: 0xC0000005: Access violation reading location 0x6c696d00.
First-chance exception at 0x762cd09c in theapp.exe: 0xC0000005: Access violation reading location 0x6c696d00.
First-chance exception at 0x762cd09c in theapp.exe: 0xC0000005: Access violation reading location 0x6c696d00.
First-chance exception at 0x762cd09c in theapp.exe: 0xC0000005: Access violation reading location 0x6c696d00.
First-chance exception at 0x762cd09c in theapp.exe: 0xC0000005: Access violation reading location 0x6c696d00.
First-chance exception at 0x762cd09c in theapp.exe: 0xC0000005: Access violation reading location 0x6c696d00.
First-chance exception at 0x762cd09c in theapp.exe: 0xC0000005: Access violation reading location 0x6c696d00.
First-chance exception at 0x762cd09c in theapp.exe: 0xC0000005: Access violation reading location 0x6c696d00.
First-chance exception at 0x762cd09c in theapp.exe: 0xC0000005: Access violation reading location 0x6c696d00.
First-chance exception at 0x762cd09c in theapp.exe: 0xC0000005: Access violation reading location 0x6c696d00.
First-chance exception at 0x762cd09c in theapp.exe: 0xC0000005: Access violation reading location 0x6c696d00.
First-chance exception at 0x762cd09c in theapp.exe: 0xC0000005: Access violation reading location 0x6c696d00.
First-chance exception at 0x762cd09c in theapp.exe: 0xC0000005: Access violation reading location 0x6c696d00.
First-chance exception at 0x762cd09c in theapp.exe: 0xC0000005: Access violation reading location 0x6c696d00.
First-chance exception at 0x762cd09c in theapp.exe: 0xC0000005: Access violation reading location 0x6c696d00.
First-chance exception at 0x0050ae33 in theapp.exe: 0xC0000005: Access violation reading location 0x00000010.
Unhandled exception at 0x0050ae33 in theapp.exe: 0xC0000005: Access violation reading location 0x00000010.
在这一点上我真的很挣扎,不知道如何继续

有谁能建议我如何解决这个问题,并确定到底出了什么问题?我非常感谢你的建议

更新

这是相关代码。调试器在嵌套语句中列出的第一条cout语句上中断,用于:

        // Inside operator() :

        map<pair<int,int>,int> resultIdByStructIds;
        pair<int,int> spair (-1,-1); // Structure pair ids reusable reference.

        int nextMapEntryId = 0;
        int nextNumCandidates = 0;
        // For each remaining candidate.
        for (int ci = 0; ci < numCandidates; ) {
            // If candidate has been mapped or found not viable this mapping round,
            // move past it.
            if (candidatesDoneThisRound[ci] == currentMappingRoundId) {
                ++ci;
                continue;
            }

            Candidate candidate = candidates[ci];
            const int tId = candidate.tVertexId;
            const int pId = candidate.pVertexId;

            // Grab the result for this structure pair.
            // Create it if it doesn't exist.
            // Avoid copying as slight optimisation; simply
            // store pointer to true result instead.
            spair.first = tInfos[tId].structure->id;
            spair.second = pInfos[pId].structure->id;

            // DEBUG
            cout << "resultIdByStructIds size: " << resultIdByStructIds.size() << endl;
            for (map<pair<int,int>,int>::const_iterator ids_id = resultIdByStructIds.begin(); ids_id != resultIdByStructIds.end(); ++ids_id) {
                cout << ids_id->first.first << endl; // * Debugger breaks here.
                cout << ids_id->first.second << endl;
                cout << ids_id->second << endl;
                printf("Structures(%i,%i) => %i\n",ids_id->first.first,ids_id->first.second,ids_id->second);
            }
            //

            // code continues...
//内部运算符():
地图结果按结构;
对空间(-1,-1);//结构对ID可重用引用。
int nextMapEntryId=0;
int nextnum候选者=0;
//对于每个剩余的候选人。
对于(int ci=0;ciid;
spair.second=pInfos[pId]。结构->id;
//调试

cout一般来说,要确定应用程序崩溃的代码点,您可以在“调试/异常”下启用异常处理。在这种情况下,您可以展开最后一个分支并检查访问冲突。当然,这将在所有访问冲突时停止,而不仅仅是坏的(访问0x10)。你可以在最后一个已知的时刻打开陷阱来最小化这一点


通常情况下,您会发现一些内存使用错误。确定此类错误原因的最简单方法是使用第三方工具,如BoundChecker,当您损坏内存时,它会立即对您大喊大叫。缺少这一点,Raymond Chen的建议非常正确。找出什么对象出错,并使用“观察”窗口查看它何时发生更改。或者更有效地,当特定地址的数据发生变化时,使用数据断点功能让程序停止。

导致程序终止的不是第一次出现异常,而是未处理的异常。我不知道MSV,但不知怎的,“访问冲突”让我怀疑“代码没有问题”…你说“代码在逻辑上没有问题。”。到目前为止,所有迹象都表明代码有问题。您能给我们看一下代码行(以及前面的相关行)吗。也许前面的解决方案可以解决您的问题。好的,一些理由:“逻辑”显然是主观的;我没有发布代码,因为类有几千行。我假设,由于未处理的异常中引用的地址与前面的第一次机会异常相同,所以我应该这样描述它。Anyway、 我将发布一些代码和/或使用您提供的链接,Jamie。感谢大家的建议,我将很快再次发表评论。