我已经创建了自己的异常,但是当我尝试使用它时,我会收到一条消息,说它无法转换为我的异常
我有一个像这样的界面
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.
我已经创建了自己的异常来处理算术异常等情况,以及涉及数学规则的其他情况.但是,当我调用它时,它永远不会进入我的例外,例如,除零会转到算术异常