From b947059ccc6b29b9ed4a541b65598a714989287d Mon Sep 17 00:00:00 2001 From: Manisha Kundnani <90680330+Manishak798@users.noreply.github.com> Date: Wed, 14 Feb 2024 09:18:58 +0530 Subject: [PATCH] Add files via upload --- OOPS/exception.cpp | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 OOPS/exception.cpp 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