#include <iostream> using namespace std; int main() { int age = 15; try { if (age < 18) { throw age; } cout << "Access granted."; } catch (int myAge) { cout << "Access denied. Age is only " << myAge; } return 0; }
Click Run to execute this code.