#include <iostream>
#include <stdexcept>
#include <string>
using namespace std;
string findItem(string *array, int size, string target)
{
int index = 0;
bool found = false ;
while (!found && (index < size))
{
if (target == array[index])
found = true ;
else
index++;
}
if (!found)
throw runtime_error("Target not found in a array!");
return array[index];
}
int main(){
string stuff[5] = {"Keys", "Food", "Glasses", "Cheese", "Skeleton"};
string a_thing;
try
{
a_thing = findItem(stuff, 5, "Pants");
}
catch(runtime_error& runErr)
{
//runErr.what() still prints nothing.
cout << runErr.what() << endl;
cout << "runtime_error" << endl;
a_thing = "Nothing";
}
cout << a_thing << endl;
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8c3RkZXhjZXB0PgojaW5jbHVkZSA8c3RyaW5nPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKCnN0cmluZyBmaW5kSXRlbShzdHJpbmcgKmFycmF5LCBpbnQgc2l6ZSwgc3RyaW5nIHRhcmdldCkKewoJaW50IGluZGV4ID0gMDsKCWJvb2wgZm91bmQgPSBmYWxzZSA7CgoJd2hpbGUgKCFmb3VuZCAmJiAoaW5kZXggPCBzaXplKSkKCXsKCQlpZiAodGFyZ2V0ID09IGFycmF5W2luZGV4XSkKCQkJZm91bmQgPSB0cnVlIDsKCgkJZWxzZQoJCQlpbmRleCsrOwoJfQoKCglpZiAoIWZvdW5kKQoJCXRocm93IHJ1bnRpbWVfZXJyb3IoIlRhcmdldCBub3QgZm91bmQgaW4gYSBhcnJheSEiKTsKCglyZXR1cm4gYXJyYXlbaW5kZXhdOwp9CgoKaW50IG1haW4oKXsKCglzdHJpbmcgc3R1ZmZbNV0gPSB7IktleXMiLCAiRm9vZCIsICJHbGFzc2VzIiwgIkNoZWVzZSIsICJTa2VsZXRvbiJ9OwoKCXN0cmluZyBhX3RoaW5nOwoKCXRyeQoJewoJCWFfdGhpbmcgPSBmaW5kSXRlbShzdHVmZiwgNSwgIlBhbnRzIik7CgoJfQoKCWNhdGNoKHJ1bnRpbWVfZXJyb3ImIHJ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