您的位置:首页 > 编程语言 > Java开发

Java学习之自定义异常

2016-01-10 02:16 405 查看
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);
}
}


太久写的,知识点都没记,慢慢上传吧
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: