C++ primer introduce some functions of try block.. But it haven't a instance..
So I get the first example.
#include <iostream>
#include <stdexcept>
#include <string>
using namespace std;
int main(){
float num1, num2, result;
string ex = "divisor can't be zero";
cout << "Input two number for division: ";
cin >> num1 >> num2;
try {
// cout << num1 / num2 << endl;
if (num2 == 0) throw ex;
result = num1 / num2;
cout << result << endl;
} catch (string ex ) {
cout << ex << endl;
}
return 0;
}
how to use the catch to express the error and throw the exception by you defined.
TBD