无法在 visual studio 2012 中捕获 "ctor subscript out of range" 异常

can't catch "ctor subscript out of range" exception in visual studio 2012

我正在编写一个在 visual studio 2012 年使用向量的程序。这是我的代码中有问题的片段:

std::vector< std::vector< std::vector<Eigen::Matrix3d> > > tensor;
//some code
try
    {
        ret = tensor[x][y][z];
    }
    catch(...)
    {
        std::cout << "Index out of range!" << std::endl;
    }

当x、y 或z 超出范围时,程序将终止而不是处理异常。

是不是VS里面的一些设置有问题?

无论使用向量还是数组,使用数组索引运算符[]都不会在索引越界时抛出异常。你得到的只是未定义的行为

如果你想要边界检查然后使用std::vector and its at访问函数。