Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Gatecrasher
//g++ 7.4.0 //Gatecrasher: demonstration of user-defined exception //this code is created by Rezaul Hoque on November 15,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> #include <exception> using namespace std; void Func(); //user defined exception struct defExcept: public exception{ const char * GC() const throw () { return "Gatecrasher detected!"; } }; void Func() { int k; std::cout<<"Enter id:\n"; std::cin>>k; if (k==0) throw defExcept(); else std::cout<<"\nWelcome,you're in the list! "; } int main() { try { Func();//function containing the exception } catch(defExcept& e) { std::cout << "You’re not welcome!" << std::endl; std::cout << e.GC() << std::endl; } catch(std::exception& e) { } return 0; }
run
|
edit
|
history
|
help
0
Lockable static queue
extern
Empty C++
c++
Member function detection
random lotto number game
my template
Podejrzana karteczka :0
Do While Meteoro Agustin
Decimal to Binary