//Java 自定义异常
//自定义异常类,4个构造
package com.puckasoft.exception;
public class UserLoginFailException extends RuntimeException {
public UserLoginFailException() {
super();
}
public UserLoginFailException(String arg0, Throwable arg1) {
super(arg0, arg1); }
public UserLoginFailException(String arg0) {
super(arg0);
}
public UserLoginFailException(Throwable arg0) {
super(arg0);
}
}
//自定义异常调用类
package com.puckasoft.service;
import com.puckasoft.exception.UserLoginFailException;
public class userService {
// 单例
private static userService userservice = new userService();
public static userService NewInstance() {
return userservice;
}
public void validateUserLogin(String name, String pwd) {
if (!name.startsWith("a") || !"123456".equals(pwd)) {
throw new UserLoginFailException("登录失败");
}
}
}