#include <iostream>
#include <exception>
#include <string>
using namespace std;
class Fracao {
private:
int numerador;
int denominador;
public:
Fracao(int numerador, int denominador);
};
Fracao::Fracao(int numerador, int denominador) {
this->numerador = numerador;
if(denominador != 0) {
this->denominador = denominador;
} else {
throw "Impossivel dividir por zero";
}
}
Fracao HandleExceptionFracao(int numerador, int denominador) {
try {
Fracao f(numerador, denominador);
return f;
} catch (const char* msg) {
cerr << "Erro: " << msg << endl;
} catch(...) {
cerr << "Erro desconhecido\n";
}
}
int main() {
Fracao f1 = HandleExceptionFracao(1, 0);
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8ZXhjZXB0aW9uPgojaW5jbHVkZSA8c3RyaW5nPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKY2xhc3MgRnJhY2FvIHsKcHJpdmF0ZToKICAgIGludCBudW1lcmFkb3I7CiAgICBpbnQgZGVub21pbmFkb3I7CnB1YmxpYzoKICAgIEZyYWNhbyhpbnQgbnVtZXJhZG9yLCBpbnQgZGVub21pbmFkb3IpOwp9OwoKRnJhY2FvOjpGcmFjYW8oaW50IG51bWVyYWRvciwgaW50IGRlbm9taW5hZG9yKSB7CiAgICB0aGlzLT5udW1lcmFkb3IgPSBudW1lcmFkb3I7CiAgICBpZihkZW5vbWluYWRvciAhPSAwKSB7CiAgICAgICAgdGhpcy0+ZGVub21pbmFkb3IgPSBkZW5vbWluYWRvcjsKICAgIH0gZWxzZSB7CiAgICAgICAgdGhyb3cgIkltcG9zc2l2ZWwgZGl2aWRpciBwb3IgemVybyI7CiAgICB9Cn0KCkZyYWNhbyBIYW5kbGVFeGNlcHRpb25GcmFjYW8oaW50IG51bWVyYWRvciwgaW50IGRlbm9taW5hZG9yKSB7CiAgICB0cnkgewogICAgICAgIEZyYWNhbyBmKG51bWVyYWRvciwgZGVub21pbmFkb3IpOwogICAgICAgIHJldHVybiBmOwogICAgfSBjYXRjaCAoY29uc3QgY2hhciogbXNnKSB7CiAgICAgICAgY2VyciA8PCAiRXJybzogIiA8PCBtc2cgPDwgZW5kbDsKICAgIH0gY2F0Y2goLi4uKSB7CiAgICAgICAgY2VyciA8PCAiRXJybyBkZXNjb25oZWNpZG9cbiI7CiAgICB9Cn0KCmludCBtYWluKCkgewoJRnJhY2FvIGYxID0gSGFuZGxlRXhjZXB0aW9uRnJhY2FvKDEsIDApOwp9