如何修复此错误?在抛出 'std::bad_alloc' what() 的实例后终止调用: std::bad_alloc

How I can fix this error? terminate called after throwing an instance of 'std::bad_alloc' what(): std::bad_alloc

本文关键字:bad alloc std 实例 调用 终止 what 何修复 错误      更新时间:2023-10-16

这是代码:功能:

QString printDir2(QString path, int level)
{
int check =1;
QDir folder(path);
QString space;
QString buffer;
qDebug() <<"nivelul 1 n";
for(int i=0; 1<level; i++)
    space +="    ";
qDebug() <<"nivelul 2 n";
foreach(QFileInfo temp , folder.entryInfoList())
{
    if(check > 2)
    {
        qDebug() <<"nivelul 4 n";
        buffer += space + temp.absoluteFilePath() + "n";
        if(temp.isDir())
            buffer += printDir2(temp.absoluteFilePath(), ++level);
    }
    check++;
    qDebug() <<"nivelul 3 n";
}
return buffer;

}

在这里,我调用该函数:

QString drum="/home/sunny/Desktop/QT/descarca";
        str=printDir2(drum,0);
        qDebug()<<str<<"acesta este drumul";

如何从终端修复此 erorr:
在抛出 'std::bad_alloc' 的实例后调用终止 what(): std::bad_alloc这是我运行代码时的终端:http://s013.radikal.ru/i325/1501/e5/aade9346f0aa.png

你可能遇到了无限递归。

在调试器中运行程序。如果使用 gdb,则可以在 run 之前发出命令 catch throw 。然后,当引发异常时,调试器将停止。您可能需要up移动几次才能查看代码中的哪一行引发了异常。