File tree 1 file changed +6
-4
lines changed
1 file changed +6
-4
lines changed Original file line number Diff line number Diff line change @@ -46,7 +46,7 @@ namespace math {
46
46
*/
47
47
uint64_t iterativeFactorial (uint8_t n) {
48
48
if (n > 20 ) {
49
- throw new std::invalid_argument (" Maximum n value is 20" );
49
+ throw std::invalid_argument (" Maximum n value is 20" );
50
50
}
51
51
52
52
// 1 because it is the identity number of multiplication.
@@ -101,12 +101,14 @@ static void test() {
101
101
std::cout << " Exception test \n "
102
102
" Input: 21 \n "
103
103
" Expected output: Exception thrown \n " ;
104
+
105
+ bool wasExceptionThrown = false ;
104
106
try {
105
107
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 ;
109
110
}
111
+ assert (wasExceptionThrown);
110
112
111
113
std::cout << " All tests have passed successfully.\n " ;
112
114
}
You can’t perform that action at this time.
0 commit comments