class MyException extends Exception {
private int id;

public MyException(String message, int n) {
super(message);
id = n;
}

public int getId() {
return id;
}
}public class Exception1 {
public void regist(int i) throws MyException {
if(i < 0) {
new MyException("不能小于0地", 3);

}
System.out.println("登记人数:" + i);
}

public void m() {
try {
regist(-10);
} catch (MyException e) {
System.out.println("出错了" + e.getId());
e.printStackTrace();
}
System.out.println("操作结束");

}

public static void main(String args[]) {
Exception1 a = new Exception1();
a.m();
}}
这里说class MyException extends Exception 的 MyException是黄线,没用到,这是怎么回事,不论怎样运行都会,我是在eclipse下做的登记人数:-10
操作结束

解决方案 »

  1.   

    严重性和描述 路径 资源 位置 创建时间 标识
    The serializable class MyException does not declare a static final serialVersionUID field of type long ja/src Exception1.java 第 1 行 1252243258781 3866
      

  2.   

    public class Exception1 {
        public void regist(int i) throws MyException {
            if(i < 0) {
               throw new MyException("不能小于0地", 3);            
            }
            System.out.println("登记人数:" + i);
        }
        
      

  3.   

    不知道你什么意思输出肯定是-10
    然后就结束了。
    catch里面的肯定不打印
    因为你只是new 了个MyException
    而不是抛出
      

  4.   

    郁闷 我看了半天也没有看出来
    呵呵,原来是没throw