diff --git a/OOPS/exception.cpp b/OOPS/exception.cpp new file mode 100644 index 0000000..bcb040b --- /dev/null +++ b/OOPS/exception.cpp @@ -0,0 +1,29 @@ +#include +using namespace std; +int main() +{ + try + { + /* code */ + int age; + cout << "Enter your age: "; + cin >> age; + if (age >= 18) + { + cout << endl + << "Access granted you are old enough."; + } + else + { + throw(age); + } + } + catch (int num) + { + cout << endl + << "Access Denied - you must be at least 18 years old. "; + cout << endl + << "Age is: " << num; + } + return 0; +} \ No newline at end of file