Java学习之自定义异常

时间:2022-01-04 15:36:38
 1 package com.gh;
import java.util.Scanner;
/**
* 自定义异常
* @author ganhang
*
*/
public class ExceptionDemo {
public static void main(String[] args) throws exception {
Scanner sc = new Scanner(System.in);
System.out.println("请输入帐号aaa密码123");
String id = sc.nextLine();
int pwd = sc.nextInt();
if (!id.equals("aaa") || pwd != 123)
throw new exception("帐号或密码错误!");
else System.out.println("帐号正确!");
}
}
class exception extends Exception{
public exception(String mes){
super(mes);
}
}

太久写的,知识点都没记,慢慢上传吧