class Test implements Cloneable
{
Object o=null;
try //为什么不能这么写 try 块?
{
public Object clone()
{
o=super.clone();
return o;
}
}
catch(Exception e)
{
System.out.println(e.toString());
}
}我想让异常处理代码作用于整个类的,而不是在每个方法中都写异常处理。有一个方法是抛出异常,但抛出后异常的捕获只能放在调用函数的地方。能不能像我那么写?
{
Object o=null;
try //为什么不能这么写 try 块?
{
public Object clone()
{
o=super.clone();
return o;
}
}
catch(Exception e)
{
System.out.println(e.toString());
}
}我想让异常处理代码作用于整个类的,而不是在每个方法中都写异常处理。有一个方法是抛出异常,但抛出后异常的捕获只能放在调用函数的地方。能不能像我那么写?
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货