#include <iostream>
#include <exception>
using namespace std;
namespace MathError {
struct DivisionByZero : public std::exception {
const char* what() const throw() {
return "DivisionByZero";
}
};
}
float division(float x, float y) {
if(y == 0.0) {
throw MathError::DivisionByZero();
} else {
return x/y;
}
}
int main() {
try {
cout << "Ratio: " << division(5.0, 0.0) << endl;
} catch (MathError::DivisionByZero &e) {
cout << "Error: " << e.what() << endl;
}
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8ZXhjZXB0aW9uPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKbmFtZXNwYWNlIE1hdGhFcnJvciB7CglzdHJ1Y3QgRGl2aXNpb25CeVplcm8gOiBwdWJsaWMgc3RkOjpleGNlcHRpb24gewoJCWNvbnN0IGNoYXIqIHdoYXQoKSBjb25zdCB0aHJvdygpIHsKCQkJcmV0dXJuICJEaXZpc2lvbkJ5WmVybyI7CgkJfQkKCX07Cn0KCmZsb2F0IGRpdmlzaW9uKGZsb2F0IHgsIGZsb2F0IHkpIHsKCWlmKHkgPT0gMC4wKSB7CgkJdGhyb3cgTWF0aEVycm9yOjpEaXZpc2lvbkJ5WmVybygpOwoJfSBlbHNlIHsKCQlyZXR1cm4geC95OwoJfQp9CgppbnQgbWFpbigpIHsKCXRyeSB7CgkJY291dCA8PCAiUmF0aW86ICIgPDwgZGl2aXNpb24oNS4wLCAwLjApIDw8IGVuZGw7Cgl9IGNhdGNoIChNYXRoRXJyb3I6OkRpdmlzaW9uQnlaZXJvICZlKSB7CgkJY291dCA8PCAiRXJyb3I6ICIgPDwgZS53aGF0KCkgPDwgZW5kbDsKCX0KCQoJcmV0dXJuIDA7Cn0=