每次尝试编译Cirlce类时,都会收到“不兼容类型”错误消息,突出显示“ ShapeException”,该怎么办才能消除此错误?

圆班

   public Circle(double inRadius )throws ShapeException{ //THE EXCEPTION NAME HIGHLIGHTS
    if(inRadius <= 0.0)
    {
        throw new ShapeException("ShapeException occurred...");
    }
    radius = inRadius;


问题可以链接到我的父类/子类吗?

  public class Exception
 {
   public Exception(String msg)
   {

   }
 }


子类:

    public class ShapeException extends Exception
    {
     public ShapeException(String msg)
    {
      super(msg);
    }
    }

最佳答案

确保ShapeException扩展了REAL Exception类(即java.lang.Exception),而不是扩展的类。最好的办法就是摆脱组成的Exception

关于java - 如何修复异常代码中发生的“不兼容类型”?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/20555266/

10-12 04:57