Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
ExceptionHandling4
//g++ 7.4.0 ///////////////////////////////////////////////////////////////////////////////ExceptionHandling4: C++ exception handling //this code is created by Rezaul Hoque on June 12,2022; //contact:jewelmrh@yahoo.com;Dhaka,Bangladesh;https://rezaulhoque.wordpress.com,https://hoquestake.blogspot.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 <string> class noEmp{}; class noNeg{}; class noZero{}; class Name{ std::string nam; int x,y; public: Name(std::string n,int b,int c){if(n==" ") { try{ throw noEmp(); } catch(noEmp n) { std::cout<<"Name field can't be empty!\n"; } } if(b==0||c==0){ try { throw noZero(); } catch(noZero z){ std::cout<<"Number can't be zero. \n"; } } if(c<0||b<0){ try { throw noNeg(); } catch(noNeg z){ std::cout<<"Number can't be negative. \n"; } } nam=n; x=b; y=c; } ~Name(){} std::string getNam(){return nam;} int getId(){return x;} int getTel(){return y;} void disp(){ if(getNam() !=" "||getId()>0||getTel()>0) std::cout<<getNam()<<" "<<getId()<<" "<<getTel(); } }; int main() { Name p(" ",0,-78); p.disp(); return 0; }
run
|
edit
|
history
|
help
0
StackListHi
32bit
krack
BridgeEdge
AgeGroupHisto
Certificate Printing
Policy based smart pointer
CPP - Pointers - Ex.1
Test 7(2020)
fundamental type sizes