Java学习之自定义异常


1
package com.gh; 2 import java.util.Scanner; 3 /** 4 * 自定义异常 5 * @author ganhang 6 * 7 */ 8 public class ExceptionDemo { 9 public static void main(String[] args) throws exception { 10 Scanner sc = new Scanner(System.in); 11 System.out.println("请输入帐号aaa密码123"); 12 String id = sc.nextLine(); 13 int pwd = sc.nextInt(); 14 if (!id.equals("aaa") || pwd != 123) 15 throw new exception("帐号或密码错误!"); 16 else System.out.println("帐号正确!"); 17 } 18 } 19 class exception extends Exception{ 20 public exception(String mes){ 21 super(mes); 22 } 23 }

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

posted @ 2016-01-10 02:16  CodeNoob  阅读(372)  评论(0编辑  收藏  举报