谈自定义Exception进行错误处理
百度广告
身份验证时,我们常常要返回一个User对象,然而又要知道到底是什么地方错误。我们可以用Exception进行控制!下面是我写的一个例子,你可以加上数据库连接!
public User validate(String userName,String password) throws InvalidNameException,WrongPasswordException{
if(password.equals("java")){
}else{
}
throw new InvalidNameException();
//return null;
public static void main(String args){
User user=null;
user=l.validate("javac","java");
System.out.println("The username is invalid!");
System.out.println("The password is wrong");
if(!(user==null)){
}
}
private String userName;
this.userName=userName;
public void setUserName(String userName){
}
return userName;
}
public InvalidNameException(){
}
public WrongPasswordException(){
public User validate(String userName,String password) throws InvalidNameException,WrongPasswordException{
if(password.equals("java")){
}else{
}
throw new InvalidNameException();
//return null;
public static void main(String args){
User user=null;
user=l.validate("javac","java");
System.out.println("The username is invalid!");
System.out.println("The password is wrong");
if(!(user==null)){
}
}
private String userName;
this.userName=userName;
public void setUserName(String userName){
}
return userName;
}
public InvalidNameException(){
}
public WrongPasswordException(){
编辑推荐:
下载Word文档
温馨提示:因考试政策、内容不断变化与调整,长理培训网站提供的以上信息仅供参考,如有异议,请考生以权威部门公布的内容为准! (责任编辑:长理培训)
点击加载更多评论>>