日期:2014-05-20  浏览次数:20707 次

感觉很奇怪,希望有人帮我看看。
public class TestThrows{
void regist(int number) throws Exception{
if (number < 0){
throw new Exception("人数为负");
}
}
public static void main(String[] args){
TestThrows t = new TestThrows();
t.regist(-4);
}
}TestThrows.java:41: 错误: 未报告的异常错误Exception; 必须对其进行捕获或声明以便抛出

------解决方案--------------------
你自己写的
if (number < 0){
抛出个例外
throw new Exception("人数为负");

你传了个-4。 (t.regist(-4);)
-4小于0,于是你就抛出了例外。
由于你例外又没人catch,所以就报错了。。。 

------解决方案--------------------
有异常但是却没有处理 当然会报错