Create a class which only works for absolute numbers, if it
encounters any negative occurrence, then it throw an exception to its
handler and display errors.
Modify the above task, by creating an exception class with an error
code and corresponding error message. Code and message should be
thrown and displayed in catch block.
#include <iostream>
using namespace std;
double negative(int x) {
if (x <= 0) {
throw "negative number!";
}
return (x);
}
Comments
Leave a comment