November 11-exception Control Process

Source: Internet
Author: User
Import Java. util. hashmap; import Java. util. map; public class loginservice {private Map <string, string> map; Public loginservice () {map = new hashmap <string, string> (); map. put ("Zhang San", "123"); map. put ("Li Si", "123"); map. put ("", "123"); map. put ("Zhao six", "1234"); map. put ("Sun Qi", "1234");} public Boolean login (string name, string password) throws nouserexception, errorpswdexception {If (map. containskey (name) {string pswd = map. get (name); If (pswd. equals (password) = false) {Throw new errorpswdexception ("User Name" + name + "password is not" + password );}} else {Throw new nouserexception ("this user name is not found in dB");} return true;} public static void main (string [] ARGs) {loginservice service = new loginservice (); string name = "zhangsan 1"; string pswd = "1235"; try {Boolean passed = service. login (name, pswd); system. out. println ("welcome" + name + "to log on to the system. ");} catch (nullpointerexception e) {system. out. println ("the database is not ready. Please notify the system administrator. ");} catch (nouserexception e) {system. out. println ("username" + name + "does not exist, coming soon to the registration page");} catch (errorpswdexception e) {system. out. println ("user's" + name + "password" + pswd + "incorrect, please specify it before entering");} catch (exception e) {e. printstacktrace ();}}}

Two exception classes:

public class ErrorPswdException extends Exception{    public ErrorPswdException(String msg){        super(msg);    }}
public class NoUserException extends Exception{    public NoUserException(String msg){        super(msg);    }}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.