在Java中使用try catch时出错

时间:2014-09-04 10:20:13

标签: java

使用try / catch时遇到问题

我创建了一个名为EmptyQueueException的异常类,它从Exception

扩展而来

不幸的是,Eclipse向我抛出了一个错误:“抓住预期而不是”

public class Testclass {

    public static void main(String[] args) {
        ArrayQueue arrayy = new ArrayQueue();
        try{
            arrayy.dequeue();
          } 
        catch(EmptyQueueException s){
               // what to do here ?     
        }
    } // end main
} // end testclass

这是我的异常类:

   public class EmptyQueueException extends Exception {

    // automatically done by eclipse, what for?
    private static final long serialVersionUID = 1L; 

    public EmptyQueueException() {
    }

    public EmptyQueueException(String s){
        super("Queue is empty");
    }
}

这是我的出队方法:

  public int dequeue() throws EmptyQueueException {
    if (empty()){
        throw new EmptyQueueException();
    }
    int retour = head();
    head = ++head % array.length;
    return retour;
}

0 个答案:

没有答案