【正文】
}public static void main(String args[]) { new TestCustomizingException().manager()。 (登記失敗,出錯種類 + ())。 } public void manager() { try { regist(100)。public class TestCustomizingException { public void regist(int num) throws MyException { if (num 0) { throw new MyException(人數(shù)為負(fù)值,不合理, 3)。 } public int getId() { return idnumber。 public MyException(String message, int id) { super(message)。s name cannot be blanknullpackage test1。 } finally{ (())。 try{ ()。 } }Exception in thread main MissingValueException: A student39。 ()。 } else { name=n。 } public void setName(String n) throws MissingValueException { if(()){ throw new MissingValueException(A student39。 } public String getIdNo() { return idNo。 private String name。 }}拋出異常的方法方法名后需要加上throws語句,在方法中要有throw語句。 } /** * Constructs an codeArithmeticException/code with the specified * detail message. * * param s the detail message. */ public ArithmeticException(String s) { super(s)。 }}第4節(jié) 自定義異常/* * () 05/11/17 * * Copyright 2006 Sun Microsystems, Inc. All rights reserved. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. */package 。 continue。 } break。 if(result0 || result130){ Exception me = new Exception(年齡超出合理范圍!)。 Scanner scan = new Scanner()。 (您的年齡: + ())。public class TestThrowException{ public static void main(String[] args){ TestThrowException t = new TestThrowException()。 } catch (InputMismatchException e1) { (e1)。 } catch (ArithmeticException e) { (除數(shù)不能為0)。 double b = ()。 double a = ()。public class ArithmeticExceptionDemo { public static void main(String args[]) { Scanner sc = new Scanner()。import 。用法:catch(Exception e){ e. printStackTrace}Scanner的nextDouble()方法public double nextDouble()將輸入信息的作為一個do