36.java_exception_test

package mytext1;

class TZException extends Exception{
TZException(String str){
super(str);
}
public String toString(String msg){
String tempt="the actual exception lies:"+msg+" ";
return tempt;
}
}

class TZ{
private String message;
private static int count=0;
TZ(String msg){
count++;
message=msg;
}
public void test(int flag) throws TZException{
if(flag==1){
throw new TZException(message);
}
}
public int getcount(){
return count;
}
}

public class mytext1{
public static void main(String args[])
{
try
{
TZ obj=new TZ("test1");
obj.test(1);
}
catch(Exception e){
System.out.println(e.toString());
}
finally{
System.out.println("over");
}
}
}

原文地址:https://www.cnblogs.com/acm-icpcer/p/6647109.html