Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
ExceptInviteClass
//g++ 7.4.0 //ExceptionInviteClass: Demonstration of more than one catch specification and rethrowing exception //this code is created by Rezaul Hoque on November 14,2021;contact: jewelmrh@yahoo.com //note: codes shared by Rezaul Hoque on rextester are not for sale; they are created and shared to facilitate the algorithm learning process; many like Hoque use this platform to practice programming ;Rezaul hopes his contribution helps others to fine tune their learning; #include <iostream> class InviteList{ public: int id; InviteList(int n):id(n){ if (n==0) throw noInvite(); if (n==1) throw welcome(); if (n==2) throw limAccess(); } ~InviteList(){} class noInvite {}; class welcome {}; class limAccess {}; }; int main(){ int k; std::cout<<"Please give your id:\n"; std::cin>>k; try { InviteList i(k); std::cout<<"Your id is "<<k<<" \n"; throw;//throwing exception to outside catch blocks } catch(InviteList::noInvite) { std::cout<< "\nSorry,you’re not in the list!"; } catch(InviteList::welcome) { std::cout<<"\nWelcome, you’re in the list."; } catch(InviteList::limAccess) { std::cout<<"\nWelcome,but you have limited access!"; } //catch all exceptions with catch(...) block catch (...) { std::cout<<"\nInvalid id"; } std::cout<<"\nThank you."; return 0; }
run
|
edit
|
history
|
help
0
c++_array_size
volatile thread-safe object
char pointer in class
data locality - slow example
003#
задача new
Dar
property get set
Project Euler - 113
mergesort tree