现在的位置: 首页 > 综合 > 正文

【java】 异常处理 exception

2017年12月01日 ⁄ 综合 ⁄ 共 344字 ⁄ 字号 评论关闭
 try {
            for (UserRecord UR : list) {
                if (name.equalsIgnoreCase(UR.userName)) {
                    if (UR.handler == null) {
                        UR.handler = clienthandler;
                        return;   //use return to exit this block
                    } else {
                        throw new InterruptedException();
                    }
                }
            }
            throw new InterruptedException();
        } catch (InterruptedException e) {
            clienthandler.sendMessage("System : invalid user!");
        }

异常处理中,异常的情况使用throw抛出异常

正常的情况要使用return,否则始终都会执行到异常

抱歉!评论已关闭.