c++ - 如何找到 map.at 坠毁的位置?
问题描述
我的代码崩溃了map.at()
,这意味着它找到了一个不存在的密钥。
我在我的主要内容中发现了错误,但似乎只能捕捉到的信息
EXCEPTION: _Map_base::at
并且没有位置信息,这意味着我需要检查所有at
功能。
有没有什么方法可以捕捉到这种错误并在它崩溃的地方打印出来?
这是我的代码:
#include <iostream>
using namespace std;
void func() {
std::unordered_map<int, int> a;
cout << a.at(2) << endl;
}
void main() {
try {
func();
} catch (const std::exception& ex) {
printf("catch EXCEPTION: %s\n", ex.what()); // the mat at error catch here, How can i print the concrete location - func, in the message??????
}
}
解决方案
推荐阅读
- unit-testing - 如何在启用 --std=c++11 标志的命令行中运行 google Test
- c++-cli - C++ CLI 在打开窗口时画一条线
- r - 在 mutate() 中使用 case_when() 为因子变量创建级别
- python - 如何计算分组df的差异?
- javascript - 有没有办法在按钮或链接中调用引导程序功能?
- r - 错误:美学必须是长度1或与数据相同(4):y,填充
- spring-statemachine - Spring StateMachine 可以有多少个 StateMachine?
- python - 创建迭代器以从每个可迭代对象中一一返回元素
- python - 当我尝试使用 corsheaders 时,为什么我的应用程序会中断?
- sql - SQL:查询以按月获取结果