I wrote code with a nested try block, but I don't know why the inner try block doesn't work, and the compiler doesn't show me any errors, it compiles the code but the inner one doesn't print anything
I think you may be misunderstanding the try/catch. When you enter the outer try block if it should go wrong, oor in your case you throw an exception, it goes to the outer catch to handle the problem and then continues.
#include<iostream>
usingnamespace std;
int main()
{
enum errorList { zeroVariableError = 4213, sVGreaterThan = 5614 };
int number1 = 0, number2 = 3;
int sum = number1 + number2;
try
{
std::cout << "\nFirst try block.\n\n";
if (sum == number2 || sum == number1)
throw zeroVariableError;
std::cout << "\nSecond try block.\n";
try // <--- You never reach here because of the first "throw".
{
if (number2 > number1)
throw sVGreaterThan;
}
catch (errorList)
{
cout << "Error " << sVGreaterThan << ": second variable is greater than first one" << endl;
}
}
catch (errorList)
{
cout << "Error " << zeroVariableError << ": one of your variable's value is zero" << endl;
}
std::cout << "\nThis is where you end up next." << '\n';
}