Python异常:在调试支持stl的c++代码时,索引超出范围
Python Exception: index out of range while debuging the code c++ with support for stl with gdb
我有一个代码:
#include <list>
int f(std::list<int>& l)
{
l.clear();
int i = 0;
return i;
}
int main(int argc, char* argv[])
{
std::list<int> l;
int i = f(l);
i++;
}
我用三种方法构建它:
- g++ -g -o main1./main1.cpp
- g++ -g -o main1 - 01 ./main1.cpp
- g++ -g -o main1 -O2 ./main1.cpp
我用gdb (GNU gdb (gdb) 7.5.1)调试它,当我进入int f(std::list&l)我得到这样的输出:
Python Exception <type 'exceptions.IndexError'> list index out of range:
(gdb) Python Exception <type 'exceptions.IndexError'> list index out of range:
下面是我的gdb会话:
(gdb) bre main
Breakpoint 1 at 0x400603: file ../main1.cpp, line 11.
(gdb) r
Starting program: /home/mhd/Texts/Programming/Programms/Exercises/Linux/BruceMolayUnixLinux/Exercises/2/Head/Debug/main1
warning: no loadable sections found in added symbol-file system-supplied DSO at 0x7ffff7ffa000
warning: Could not load shared library symbols for linux-vdso.so.1.
Do you need "set solib-search-path" or "set sysroot"?
(gdb) n
(gdb) n
(gdb) s
Python Exception <type 'exceptions.IndexError'> list index out of range:
(gdb) Python Exception <type 'exceptions.IndexError'> list index out of range:
q
Debugger finished
如何防止此异常?为什么要抛出异常?
您可以通过禁用有问题的漂亮打印机来防止此异常。
相关文章:
- 数组索引的值没有增加
- C++我的数学有什么问题,为什么我的代码不能正确循环
- 代码在main()中运行,但在函数中出现错误
- 在VS代码中交叉编译Windows与Linux上的MinGW的SDL程序
- 编译包含字符串的代码时遇到问题
- 我在c++代码中生成了一个运行时#3异常
- 如何在linux终端中同时编译和运行c++代码
- 为cl.exe(Visual Studio代码)指定命令行C++版本
- 在Linux for Windows上编译C++代码时出错
- 我的字符计数代码计算错误.为什么
- 修改链表主函数代码,用户将在其中输入节点的索引和数据以及正确的消息
- 为什么我的代码没有对数组中第二个索引上的数据进行排序?
- 此代码如何启动索引为 1 的 C 样式字符串
- Visual Studio是否支持C++代码索引
- 一些测试用于查看为使用指针的迭代和使用索引的迭代生成的代码是否不同
- Eclipse CDT:强制索引条件编译的代码
- 在c++ AMP限制(direct3d)代码中使用int索引,其中double是预期的
- Python异常:在调试支持stl的c++代码时,索引超出范围
- 代码未返回正确的索引
- 为什么代码打印所有第一个索引