File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -46,7 +46,7 @@ namespace math {
4646 */
4747uint64_t iterativeFactorial (uint8_t n) {
4848 if (n > 20 ) {
49- throw new std::invalid_argument (" Maximum n value is 20" );
49+ throw std::invalid_argument (" Maximum n value is 20" );
5050 }
5151
5252 // 1 because it is the identity number of multiplication.
@@ -101,12 +101,14 @@ static void test() {
101101 std::cout << " Exception test \n "
102102 " Input: 21 \n "
103103 " Expected output: Exception thrown \n " ;
104+
105+ bool wasExceptionThrown = false ;
104106 try {
105107 math::iterativeFactorial (21 );
106- } catch (std::invalid_argument* e) {
107- std::cout << " Exception thrown successfully \n Content: " << e->what ()
108- << " \n " ;
108+ } catch (const std::invalid_argument&) {
109+ wasExceptionThrown = true ;
109110 }
111+ assert (wasExceptionThrown);
110112
111113 std::cout << " All tests have passed successfully.\n " ;
112114}
You can’t perform that action at this time.
0 commit comments