正在加载图片...
0-6 class Worker{/定义一个可以抛出Exceptl,.Except2异常的方法 public void fl(int val)throws Except1,Except2{ switch (val){ casel:throw new Exceptl("Gotcha!"); case2:throw new Except2(“Againnn”);} class Except1 extends Exception{/定义Exceptl异常 private String theMessage; public Except1(String aMsg){ theMessage aMsg; public String toString(){ return“Except1”+theMessage;}10-6 Programming in Java class Worker {//定义一个可以抛出Except1, Except2 异常的方法 public void f1(int val) throws Except1, Except2 { switch (val) { case1: throw new Except1(“Gotcha!”); case2: throw new Except2(“Againnn”); } } } class Except1 extends Exception {//定义Except1异常 private String theMessage; public Except1(String aMsg) { theMessage = aMsg; } public String toString() { return “Except1” + theMessage; } 示例(1)
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有