Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8153841
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T16:09:03+00:00 2026-06-06T16:09:03+00:00

Why can’t I catch this exception? My (client) code: Eigen::MatrixXd FFs ; try {

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T16:09:04+00:00Added an answer on June 6, 2026 at 4:09 pm

    The problem was the exception being thrown by resize() was std::exception. However, the code in the question explicitly tries to capture exceptions of type int. This won’t work and the catch block will be passed.

    One way to fix this is by using a general “catch all” block:

    try
    {
      FFs.resize( NUMPATCHES, NUMPATCHES ) ;
    }
    catch(...) // catch all exceptions, no type declaration required
    {
      error( "Not enough memory :(" ) ;
      return ;
    }
    

    The ellipses in the catch(...) statement mean you don’t have to resolve exception type. All exceptions will be caught, regardless of type.

    However this appears to be not recommended. This may be analogous to the generic catch( Exception e ) statements in Java and C#, which is frowned upon in those languages for reasons stated here.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

can someone explain why the compiler accepts only this code template<typename L, size_t offset,
Can someone thoroughly explain the last line of the following code: def myMethod(self): #
Can anyone explain to me why this program: for(float i = -1; i <
Can I run this in a Windows command prompt like I can run it
Can anybody help me? What should be the datatype for this type -07:00:00 of
Can't figure out how to do this in a pretty way : I have
Can someone please explain why this doesn't work? MyClass myClass1 = new MyClass(); object
Can someone help me with this scenario? *There is a button, which when tapped,
Can anyone explain me what's going on? I use this method - (BOOL)shouldAutorotateToInterfaceOrientation:( UIInterfaceOrientation)interfaceOrientation
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.