Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
ExceptionWhat
//g++ 7.4.0 //ExceptionWhat: Demonstration of what() defined in header file exception //this code is created by Rezaul Hoque on November 16,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; class noInvite : public exception { public: noInvite(): text("\nYou are not welcome!"){} ~noInvite(){} const char* what() const noexcept { return text;} private: const char* text; }; class welcome: public exception { public: welcome():t("\nWelcome,you're in the list!"){} ~welcome(){} const char* what()const noexcept{return t;} private: const char* t; }; void Func(){ int k; std::cout<<"Enter id:\n"; std::cin>>k; if (k==0) throw noInvite(); else throw welcome(); } int main() { try{ Func(); } catch(noInvite no) { std::cout<<"Gatecrasher detected!"<<std::endl; std::cout<<no.what()<<std::endl; std::cout<<"Sorry, only for invited!"<<std::endl; } catch(welcome s) { std::cout<<s.what()<<std::endl; } std::cout<<"Thank you!"<<std::endl; return 0; }
run
|
edit
|
history
|
help
0
Sorting sort function stl in c++
tes
Wuninitialized
newwork
fastest input taking for large files
Double_wrapper gcc
BintTree vertical sum
HW0
Generating π from 1,000 random numbers
C++ Array printing