Why can't I catch this exception?
My (client) code:
Eigen::MatrixXd FFs ;
try
{
FFs.resize( NUMPATCHES, NUMPATCHES ) ;
}
catch( int e )
{
error( "Not enough memory :(" ) ;
return ;
}
The Eigen code that throws the exception is a few levels down..
EIGEN_STRONG_INLINE void resize(Index rows, Index cols)
{
internal::check_rows_cols_for_overflow(rows, cols);
m_storage.resize(rows*cols, rows, cols);
}
Which calls
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;
}
The bolded lines are the ones that get hit before the line:
throw std::bad_alloc();
gets hit, which happens somewhere inside the internal::conditional_aligned_delete_auto(m_data, m_rows*m_cols); function call.
Why can't I catch this exception from my client code? Is it because the Eigen library didn't mark the resize function with throws? How can I make this code using the Eigen library recover from this malloc type error smoothly?