首先自定义一个异常类
public class ActionException extends Exception{
public String returnMessage;
public ActionException(String returnMessage){
this.returnMessage = returnMessage;
}
public String getReturnMessage(){
return this.returnMessage;
}
代码中如果用到这个自定义的异常类,这里的代码只是做了个演示
private void validate(int a,int b)throws ActionException{
if(a>b){
throw new ActionException("a > b");
}
if(a<b){
throw new ActionException("a < b");
}
}
业务逻辑代码中
public String process(){
try{
validate(a,b);
}catch(ActionException ae){
System.out.println(ae.getReturnMessage());
}
}
追问主函数写哪儿啊?
本回答被提问者采纳