Menu

catching assert()

2008-09-12
2013-04-22
  • charles tremblay

    Hi,

    I'm wondering if there is a way to catch assert from within cppUnit?,  i would like to catch those and continue with other test.

    There problem her is that often when testing error case there is an assert in the called function to prevent such a ''mistake''. Then the test are stopped. In a batch environment were we need to run multiple test, this is a problem

    Can we put an errorHandler

    Thanks,

     
    • Jannich Thorsen

      Jannich Thorsen - 2008-11-18

      Hi,
      In our unittests (running on Linux) we override the assert handler like this, to 'convert' an assert into an exception:

      void __assert_fail (const char *assertion, const char *file, unsigned int line, const char *function) {
        throw my_exceptions::Exception("assert_handler");
      }

      Note: This requires gcc version 4.1.2 or newer to work correctly.

      Regards
      Jannich

       

Log in to post a comment.