为什么我不能捕捉到这个异常?如何捕获Eigen的MatrixXd :: resize()函数抛出的异常?
我(客户端)代码:
Eigen::MatrixXd FFs ;
try
{
FFs.resize(NUMPATCHES, NUMPATCHES) ;
}
catch(int e)
{
error("Not enough memory :(") ;
return ;
}
抛出异常是几级沿着征代码..
EIGEN_STRONG_INLINE void resize(Index rows, Index cols) { internal::check_rows_cols_for_overflow(rows, cols); m_storage.resize(rows*cols, rows, cols); }
其中要求
void resize(DenseIndex size, DenseIndex rows, DenseIndex cols) { if(size != m_rows*m_cols) { internal::conditional_aligned_delete_auto(m_data, m_rows*m_cols); if (size) m_data = internal::conditional_aligned_new_auto(size); else m_data = 0; EIGEN_INTERNAL_DENSE_STORAGE_CTOR_PLUGIN } m_rows = rows; m_cols = cols; }
的粗线是在线前击中的那些:
throw std::bad_alloc();
被击中,这发生在internal::conditional_aligned_delete_auto(m_data, m_rows*m_cols);
函数调用的某处。
为什么我无法从我的客户端代码中捕获此异常?是否因为特征库没有用throws
标记resize
函数?我怎样才能使这个代码使用Eigen库从这个malloc
类型错误中顺利恢复?
Erm,因为catch(int)不能捕获std :: bad_alloc吗? –
嗯,我应该注意,我从来没有使用C++异常 – bobobobo