package oj512;
import java.util.Scanner;
public class DIY {
public static void main(String[]args) {
//实现登录验证
Scanner bb=new Scanner(System.in);
String name=bb.nextLine();
code a=new code();
try {
a.diy(name);
} catch (CodeException e) {
// TODO Auto-generated catch block
//e.printStackTrace();
System.out.println(“登录失败,原因是:用户名不存在”);
}//上一行用来返回错误信息和位置
}
}
class code{
public String name;
public code(String name) {
this.name=name;
}
public code() {
// TODO Auto-generated constructor stub
}
public void diy(String name)throws CodeException
//构造一个throw错误的方法
{
if(name.equals(“john”))
System.out.println(“登录成功!”);
else {
throw new CodeException(“登录失败,原因是:用户名不存在”);}
}//错误信息描述
}
class CodeException extends Exception{
public CodeException() {
}
public CodeException(String message) {
super(message);
}
}