I'm trying to write a program that prints the second smallest integer in a sequence and outputs an error message if there is no second smalles integer (e.g. in 2 2 2 2)
I got the code to work with valid input. I can't figure out how to implement the try throw and catch. Code is down below, any help will be appreciated :)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
for (int i = 0; i < order.size(); i++) {
if (order[i] < small) {
second = small;
small = order[i];
}
elseif (order[i] < second) {
second = order[i];
}
if (order[i] = order[i]) {
try {
throw std::runtime_error("error: no second smallest");
}
catch (std::runtime_error error) {
std::cerr << error.what() << std::endl;
}
}
}