自定义的异常类 package com.jin.www; public class MyException extends Exception{ private int detail; public MyException(int a) { this.detail=a; } public String toString() { return "MyException{"+detail+"}"; } } package com.jin.www; public class Demo02 { static void text(int a)throws MyException{ System.out.println("传递的参数为:"+a); if(a>10) { throw new MyException(a); } System.out.println("OK"); } public static void main(String[] args) { try { text(11); }catch(MyException e){ System.out.println("MyException=>"+e); } } } //输出: //传递的参数为:11 //MyException=>MyException{11}