Advertisement
Guest User

Untitled

a guest
May 14th, 2018
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.67 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3.  
  4. using namespace std;
  5.  
  6. class LoginException{
  7. private:
  8. string login;
  9. public:
  10. LoginException(string u=""):login(u){}
  11. string getLogin() const {return login;}
  12. };
  13.  
  14. int main(){
  15. string uname, pwd;
  16. cout << "User => ";
  17. cin >> uname;
  18.  
  19. cout << "Password => ";
  20. cin >> pwd;
  21.  
  22. try{
  23. if ( uname.compare("abc")==0 && pwd.compare("abc")==0){
  24. cout << "Login ok..." << endl;
  25. }
  26. else throw LoginException(uname);
  27. }
  28. catch (LoginException e) {
  29. cout << "Invalid username or password: username=" << e.getLogin() << endl;
  30. }
  31. catch (...){
  32. cout << "Unknown error has occured" << endl;
  33. }
  34.  
  35. return 0;
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement