Junior — Senior
What will the program with multiple catch blocks output
livecode
Task condition
It is necessary to predict which set of characters will appear in the standard output after executing the following program.
#include <iostream>
using namespace std;
struct boom_exception : public std::exception {};
struct primary_exception : public std::exception {};
struct Explosive
{
~Explosive()
{
// destructor does nothing
}
};
int main()
{
try
{
Explosive explosiveObj;
throw primary_exception();
}
catch (const std::exception&)
{
cout << "1";
// handler 1
}
catch (primary_exception&)
{
cout << "2";
// handler 2
}
catch (boom_exception&)
{
cout << "3";
// handler 3
}
catch (int&)
{
cout << "4";
// handler 4
}
return 0;
}