0

I don’t understand this

What’s throw, try, and catch? Why does try not output anything? Why does throw fail when 0? Why does throw fail when removing the if statement? int func (int i = 0){ if(!i)throw 1; return i+1; } int main() { try { cout << func(); } catch(int i) { cout << func(i); } }

19th Aug 2023, 2:44 PM
Caleb Benitez
Caleb Benitez - avatar
2 odpowiedzi
+ 2
Try, throw, and catch are the 3 keywords used to catch errors found in your code. #Not explaining the throw keyword because I'm still learning! The try keyword defines where the error would triggers if a problem occurs inside its block. If no errors were found, it would execute its block normally. The catch keyword would execute if the try block next to it generates an error. if-else staments aren't used to catch errors, because it is not programmed to do so.
19th Aug 2023, 4:33 PM
Dragon RB
Dragon RB - avatar
+ 1
「HAPPY TO HELP」 I guess I learned something new in C++ now. Thanks! ❝ 「I really liked your abandoned games project tho..」❞
19th Aug 2023, 4:39 PM
Dragon RB
Dragon RB - avatar