Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- using namespace std;
- class LoginException{
- private:
- string login;
- public:
- LoginException(string u=""):login(u){}
- string getLogin() const {return login;}
- };
- int main(){
- string uname, pwd;
- cout << "User => ";
- cin >> uname;
- cout << "Password => ";
- cin >> pwd;
- try{
- if ( uname.compare("abc")==0 && pwd.compare("abc")==0){
- cout << "Login ok..." << endl;
- }
- else throw LoginException(uname);
- }
- catch (LoginException e) {
- cout << "Invalid username or password: username=" << e.getLogin() << endl;
- }
- catch (...){
- cout << "Unknown error has occured" << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement