+ 1
I want to make that when someone tries to divide by 0,the output says:you can't, or something like that.How can i do it?(solved)
8 Answers
+ 7
https://www.sololearn.com/learn/CPlusPlus/1918/?ref=app
+ 12
I don't know much c++ but as far as other languages are concerned u can use exception handling and can display required message.
You can use try block and catch block.
+ 5
Arushi Singhania that's exactly how it works in C++ too..
CrazySun03 you can use "assert" from <cassert> too.
Like this.. assert("you can't do something like that");
+ 5
If u will not use try and catch, throw will throw an error and ur programme will terminate. To catch that error and to display some msg and to stop ur programme from creating error, you need try and catch block
+ 5
In this case, insert division algorithm in try block that is the part which will throw exception. After it, open catch block, specify the type of exception in parenthesis and then in curly braces, write what u want to display in case of that error.
+ 2
Muhd Khairul Amirin Bin Yaacob Arushi Singhania Thank you so much, but i don't get why 'try' and 'catch' are useful. I think i can do the same with only throw.
Where i can use try and catch?
+ 1
Peter.. Can you please be a little more specific? i'm new on c++.
When i should use assert?
+ 1
Arushi Singhania Thx, but how should i use try and catch? where? when?