try catch finally throw throwsctrl+alt+T
public class MyException extends Exception { //传递数字>10 private int detail; public MyException(int a) { // super(message); this.detail = a; } //异常的打印信息 @Override public String toString() { return "MyException{" + "detail=" + detail + '}'; } }
public class Test { //可能存在异常的方法 static void test(int b) throws MyException { System.out.println("传递的参数为:"); if (b>10){ throw new MyException(b); } System.out.println("ok"); } public static void main(String[] args) { try { test(17); } catch (MyException e) { System.out.println("MyException=>"+e); }finally { System.out.println("继续"); } }
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)