diff --git a/src/Macros.hpp b/src/Macros.hpp index aa8fe6f4..544f5e19 100644 --- a/src/Macros.hpp +++ b/src/Macros.hpp @@ -180,6 +180,12 @@ } \ } while( false ) +/** + * @brief Throw an exception. + * @param MSG The message to associate with the error, can be anything streamable to a std::ostream. + */ +#define LVARRAY_THROW( MSG, TYPE ) LVARRAY_THROW_IF( true, MSG, TYPE ) + /// Assert @p EXP is true with no message. #define LVARRAY_ASSERT( EXP ) LVARRAY_ASSERT_MSG( EXP, "" ) diff --git a/src/input.hpp b/src/input.hpp index fde15d56..12cc033a 100644 --- a/src/input.hpp +++ b/src/input.hpp @@ -62,9 +62,10 @@ struct StringToArrayHelper { inputStream >> arrayValue; - LVARRAY_ERROR_IF( inputStream.fail(), + LVARRAY_THROW_IF( inputStream.fail(), "Invalid value of type " << typeid(T).name() << " in: " << - ( inputStream.eof() ? "" : inputStream.str().substr( inputStream.tellg() ) ) ); + ( inputStream.eof() ? "" : inputStream.str().substr( inputStream.tellg() ) ), + std::invalid_argument ); } /** @@ -79,7 +80,8 @@ struct StringToArrayHelper INDEX_TYPE const * const dims, std::istringstream & inputStream ) { - LVARRAY_ERROR_IF( inputStream.peek() != '{', "opening { not found for input array: "<( valueString.find_first_not_of( '{' )); - LVARRAY_ERROR_IF( ndims!=NDIM, + LVARRAY_THROW_IF( ndims!=NDIM, "number of dimensions in string ("< array; - EXPECT_DEATH_IF_SUPPORTED( input::stringToArray( array, input ), IGNORE_OUTPUT ); + ASSERT_THROW( input::stringToArray( array, input ), std::invalid_argument ); } { input = " { { 1, 2 }{ 3, 4 } } "; ArrayT< int, RAJA::PERM_IJ > array; - EXPECT_DEATH_IF_SUPPORTED( input::stringToArray( array, input ), IGNORE_OUTPUT ); + ASSERT_THROW( input::stringToArray( array, input ), std::invalid_argument ); } // This should fail the num('{')==num('}') test { input = " { { {0,1,2},{3,4,5} }, { {6,7,8},{9,10,11} }, { {12,13,14},{15,16,17} } , { {18,19,20},{21,22,23} } "; ArrayT< int, RAJA::PERM_IJK > array; - EXPECT_DEATH_IF_SUPPORTED( input::stringToArray( array, input ), IGNORE_OUTPUT ); + ASSERT_THROW( input::stringToArray( array, input ), std::invalid_argument ); } { input = " { { {0,1,2},{3,4,5} }, { {6,7,8},{9,10,11} }, { {12,13,14},{15,16,17} , { {18,19,20},{21,22,23} } }"; ArrayT< int, RAJA::PERM_IKJ > array; - EXPECT_DEATH_IF_SUPPORTED( input::stringToArray( array, input ), IGNORE_OUTPUT ); + ASSERT_THROW( input::stringToArray( array, input ), std::invalid_argument ); } { input = " { { {0,1,2},{3,4,5} }, { {6,7,8},{9,10,11} }, { {12,13,14,{15,16,17} } , { {18,19,20},{21,22,23} } }"; ArrayT< int, RAJA::PERM_JIK > array; - EXPECT_DEATH_IF_SUPPORTED( input::stringToArray( array, input ), IGNORE_OUTPUT ); + ASSERT_THROW( input::stringToArray( array, input ), std::invalid_argument ); } { input = " { { {0,1,2},{3,4,5} }, { {6,7,8,{9,10,11} }, { {12,13,14},{15,16,17} } , { {18,19,20},{21,22,23} } }"; ArrayT< int, RAJA::PERM_JKI > array; - EXPECT_DEATH_IF_SUPPORTED( input::stringToArray( array, input ), IGNORE_OUTPUT ); + ASSERT_THROW( input::stringToArray( array, input ), std::invalid_argument ); } { input = " { { 0,1,2},{3,4,5} }, { {6,7,8},{9,10,11} }, { {12,13,14},{15,16,17} } , { {18,19,20},{21,22,23} } }"; ArrayT< int, RAJA::PERM_KIJ > array; - EXPECT_DEATH_IF_SUPPORTED( input::stringToArray( array, input ), IGNORE_OUTPUT ); + ASSERT_THROW( input::stringToArray( array, input ), std::invalid_argument ); } { input = " { {0,1,2},{3,4,5} }, { {6,7,8},{9,10,11} }, { {12,13,14},{15,16,17} } , { {18,19,20},{21,22,23} } "; ArrayT< int, RAJA::PERM_KJI > array; - EXPECT_DEATH_IF_SUPPORTED( input::stringToArray( array, input ), IGNORE_OUTPUT ); + ASSERT_THROW( input::stringToArray( array, input ), std::invalid_argument ); } { input = " { { {,1,2},{3,4,5} }, { {6,7,8},{9,10,11} }, { {12,13,14},{15,16,17} } , { {18,19,20},{21,22,23} } }"; ArrayT< int, RAJA::PERM_IJK > array; - EXPECT_DEATH_IF_SUPPORTED( input::stringToArray( array, input ), IGNORE_OUTPUT ); + ASSERT_THROW( input::stringToArray( array, input ), std::invalid_argument ); } { input = " { { {},{3,4,5} }, { {6,7,8},{9,10,11} }, { {12,13,14},{15,16,17} } , { {18,19,20},{21,22,23} } }"; ArrayT< int, RAJA::PERM_IJK > array; - EXPECT_DEATH_IF_SUPPORTED( input::stringToArray( array, input ), IGNORE_OUTPUT ); + ASSERT_THROW( input::stringToArray( array, input ), std::invalid_argument ); } { input = " { { {0,1,2}}{ } }"; ArrayT< int, RAJA::PERM_IJK > array; - EXPECT_DEATH_IF_SUPPORTED( input::stringToArray( array, input ), IGNORE_OUTPUT ); + ASSERT_THROW( input::stringToArray( array, input ), std::invalid_argument ); }