日期:2014-05-20 浏览次数:20877 次
class MyException extends Exception
{
private int detail;
public MyException(int a){
detail = a;
}
@Override public String toString(){
return "MyException" + detail;
}
}
public class ExceptionDemo{
public static void compute(int a) throws MyException {
System.out.println("called compute("+a+")");
if(a>10)
throw new MyException(a);
System.out.println("normal exit");
}
public static void main( String args[] ){
try {
compute(6 );
compute( 12 );
}
catch(MyException e){
System.out.println("Caught "+e);
}
}
}
------解决方案--------------------
public class Test extends TT {
public static void main(String args[]){
Test t = new Test("Tom");
}
public Test(String s){
super(s);
System.out.println("How do you do?");
}
public Test(){
this("I am Tom");
}
}
class TT{
public TT(){
System.out.println("What a pleasure!");
}
public TT(String s){
this();
System.out.println("I am "+s);
}
}