zoukankan      html  css  js  c++  java
  • JAVA异常

    JAVA异常

    AccountNotFoundException类

    package com.blueleson.hello;

    public class AccountNotFoundException extends Exception {

       public AccountNotFoundException(String message) {
           super(message);
       }

       @Override
       public String getMessage() {
           return "账号未找到";
       }
    }

    login类

    package com.blueleson.hello;

    public class User {
        public void login(String account, String password)
                throws AccountNotFoundException {
            boolean accountExisted = false; // 默认帐号不存在
            String otherPassword;
            // 此处可插入查询帐号的代码
            if (accountExisted) { // 如果帐号不存在,抛出异常,程序中断
                throw new AccountNotFoundException(account);
           }
       }
        public static void main(String[] args) {
            User user = new User();
            try {
                user.login("account", "password");
           } catch (AccountNotFoundException e) {
                //插入处理帐号不存在的代码
                System.out.println(e.getMessage());
                System.exit(-1);
           }
            //插入登陆成功的代码
            System.out.println("登陆成功!");
       }

    }
  • 相关阅读:
    [JSOI2015]染色问题
    [ZJOI2016]小星星
    [BZOJ4361]isn
    [BZOJ4043/CERC2014]Vocabulary
    [BZOJ3622]已经没有什么好害怕的了
    [BZOJ2958]序列染色
    [SDOI2013]spring
    [Usaco2012 Nov]Concurrently Balanced Strings
    php常用函数集合
    制作item和category的mvc视图总结
  • 原文地址:https://www.cnblogs.com/ltyandy/p/11544582.html
Copyright © 2011-2022 走看看