Commit 1cdceeb4da0a4f05c2a53ed6e69fef7822a6a709

Authored by Jürgen Knödlseder
1 parent 4711eaa6

Improve nested try exceptions.

Showing 1 changed file with 14 additions and 4 deletions
src/test/GTestSuite.cpp
... ... @@ -47,8 +47,9 @@ pthread_attr_t gomp_thread_attr;
47 47 /* __ Method name definitions ____________________________________________ */
48 48 #define G_OP_ACCESS "GTestSuite::operator[](int&)"
49 49 #define G_TRY_SUCCESS "GTestSuite::test_try_success()"
50   -#define G_TRY_FAILURE "GTestSuite::test_try_failure(std::string&,"\
  50 +#define G_TRY_FAILURE1 "GTestSuite::test_try_failure(std::string&,"\
51 51 "std::string&)"
  52 +#define G_TRY_FAILURE2 "GTestSuite::test_try_failure(std::exception&)"
52 53  
53 54 /* __ Macros _____________________________________________________________ */
54 55  
... ... @@ -624,7 +625,7 @@ void GTestSuite::test_try_success(void)
624 625 // If the stack is empty
625 626 if (m_stack_try.size() == 0) {
626 627 throw GException::test_nested_try_error(G_TRY_SUCCESS,
627   - "Called test_try_success() without a previous call to test_try()");
  628 + "Called "G_TRY_SUCCESS" without a previous call to test_try()");
628 629 }
629 630  
630 631 // Add test case to test suite
... ... @@ -671,8 +672,8 @@ void GTestSuite::test_try_failure(const std::string& message,
671 672 {
672 673 // If the stack is empty
673 674 if (m_stack_try.size() == 0) {
674   - throw GException::test_nested_try_error(G_TRY_FAILURE,
675   - "Called test_try_failure() without a previous call to test_try()");
  675 + throw GException::test_nested_try_error(G_TRY_FAILURE1,
  676 + "Called "G_TRY_FAILURE1" without a previous call to test_try()");
676 677 }
677 678  
678 679 // Signal that test is not ok
... ... @@ -709,6 +710,9 @@ void GTestSuite::test_try_failure(const std::string& message,
709 710 *
710 711 * @param[in] exception Exception.
711 712 *
  713 + * @exception GException::test_nested_try_error
  714 + * Test case index is out of range.
  715 + *
712 716 * @see test_try_sucess()
713 717 * @see test_try(const std::string& name)
714 718 * @see test_try_failure(const std::string& message, const std::string& type)
... ... @@ -727,6 +731,12 @@ void GTestSuite::test_try_failure(const std::string& message,
727 731 ***************************************************************************/
728 732 void GTestSuite::test_try_failure(const std::exception& e)
729 733 {
  734 + // If the stack is empty
  735 + if (m_stack_try.size() == 0) {
  736 + throw GException::test_nested_try_error(G_TRY_FAILURE2,
  737 + "Called "G_TRY_FAILURE2" without a previous call to test_try()");
  738 + }
  739 +
730 740 // Extract message of exception and class name
731 741 test_try_failure(e.what(), typeid(e).name());
732 742  
... ...