#include <iostream>
#include <stdexcept>
using namespace std;
double divideNumbers(double inNumberator, double inDenominator) {
if (inDenominator == 0)
throw std::exception();
return (inNumberator / inDenominator);
}
int main(int argc, char *argv[])
{
try {
std::cout << divideNumbers(2.5, 0.5) << std::endl;
std::cout << divideNumbers(2.3, 0) << std::endl;
} catch (std::exception excepiton) {
std::cout << "An exception was caught!" << std::endl;
}
return 0;
}
#include <stdexcept>
using namespace std;
double divideNumbers(double inNumberator, double inDenominator) {
if (inDenominator == 0)
throw std::exception();
return (inNumberator / inDenominator);
}
int main(int argc, char *argv[])
{
try {
std::cout << divideNumbers(2.5, 0.5) << std::endl;
std::cout << divideNumbers(2.3, 0) << std::endl;
} catch (std::exception excepiton) {
std::cout << "An exception was caught!" << std::endl;
}
return 0;
}
output:
5
An exception was caught!