小编alc*_*ete的帖子

处理异常的问题

我已经创建了自己的异常,但是当我尝试使用它时,我会收到一条消息,说它无法转换为我的异常

我有一个像这样的界面

public interface MyInterface
{   
    public OtherClass generate(ClassTwo two, ClassThree three) throws RetryException;
}
Run Code Online (Sandbox Code Playgroud)

其他像这样的

public class MyGenerator{   
  public class generate (ClassTwo two, ClassThree three){
    try{
    }catch(MyException my)
  }
}
Run Code Online (Sandbox Code Playgroud)

最后是另一个类中的方法

public Object evaluate(String expression, Map values) throws FirstException, RetryException
{
   try{
   }catch (Exception x){
     if(x instanceof FirstException){
       throw new FirstException()
     }
     else{
       RetryException retry= (RetryException)x;
       retry.expression = expression;
       retry.position = position;
       retry.operator = tokens[position];
       retry.operand = 1;
       throw retry; 
     }
  }
}
Run Code Online (Sandbox Code Playgroud)

这个try catch块在最后一个方法是进行数学运算,我想在上面捕获一个除零异常RetryException.

java exception

5
推荐指数
1
解决办法
167
查看次数

处理算术异常

我已经创建了自己的异常来处理算术异常等情况,以及涉及数学规则的其他情况.但是,当我调用它时,它永远不会进入我的例外,例如,除零会转到算术异常

java exception

4
推荐指数
1
解决办法
4270
查看次数

标签 统计

exception ×2

java ×2