Java でいくつかの関数を使用してスタックを実装しようとしています。次のように Exception を実装するクラス UnderflowException を作成しました。
package exceptions;
public class UnderflowException extends Exception
{
public UnderflowException(String err)
{
super(err);
}
}
インターフェイスを実装しているときに 、スローしようとすると、「UnderflowException 型の例外はスローできません。例外型は Throwable のクラスである必要があります」というエラーが表示されます。
私のインターフェースは次のようになります。
import exceptions.*;
public interface Stack
{
public void push(Object x);
public void pop() throws UnderflowException;
public Object top() throws UnderflowException;
//other functions
}
UnderflowException クラスに問題はありますか? ありがとうございました!