#include <iostream>
#include <stdexcept>
using namespace std;
void exampleFunction(int value) {
if (value == 0) {
throw runtime_error("Runtime error: value cannot be zero");
}
else if (value < 0) {
throw invalid_argument("Invalid argument: value cannot be negative");
}
else {
cout << "Value is valid" << endl;
}
}
int main() {
try {
exampleFunction(0); // This will throw a runtime_error
}
catch (const invalid_argument& e) {
cout << "Caught exception: " << e.what() << endl;
}
catch (const runtime_error& e) {
cout << "Caught exception: " << e.what() << endl;
}
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8c3RkZXhjZXB0PgoKdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCnZvaWQgZXhhbXBsZUZ1bmN0aW9uKGludCB2YWx1ZSkgewogICAgaWYgKHZhbHVlID09IDApIHsKICAgICAgICB0aHJvdyBydW50aW1lX2Vycm9yKCJSdW50aW1lIGVycm9yOiB2YWx1ZSBjYW5ub3QgYmUgemVybyIpOwogICAgfQogICAgZWxzZSBpZiAodmFsdWUgPCAwKSB7CiAgICAgICAgdGhyb3cgaW52YWxpZF9hcmd1bWVudCgiSW52YWxpZCBhcmd1bWVudDogdmFsdWUgY2Fubm90IGJlIG5lZ2F0aXZlIik7CiAgICB9CiAgICBlbHNlIHsKICAgICAgICBjb3V0IDw8ICJWYWx1ZSBpcyB2YWxpZCIgPDwgZW5kbDsKICAgIH0KfQoKaW50IG1haW4oKSB7CiAgICB0cnkgewogICAgICAgIGV4YW1wbGVGdW5jdGlvbigwKTsgIC8vIFRoaXMgd2lsbCB0aHJvdyBhIHJ1bnRpbWVfZXJyb3IKICAgIH0KICAgIGNhdGNoIChjb25zdCBpbnZhbGlkX2FyZ3VtZW50JiBlKSB7CiAgICAgICAgY291dCA8PCAiQ2F1Z2h0IGV4Y2VwdGlvbjogIiA8PCBlLndoYXQoKSA8PCBlbmRsOwogICAgfQogICAgY2F0Y2ggKGNvbnN0IHJ1bnRpbWVfZXJyb3ImIGUpIHsKICAgICAgICBjb3V0IDw8ICJDYXVnaHQgZXhjZXB0aW9uOiAiIDw8IGUud2hhdCgpIDw8IGVuZGw7CiAgICB9CgogICAgcmV0dXJuIDA7Cn0K