Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/393.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 无法将use def异常转换为可丢弃错误 公共类OdeException扩展异常{ 双赤字; Odexception(字符串消息,双定义){ 超级(味精); 这个.赤字=def; } } 公共作废撤销(双倍金额)引发异常{ 如果(amt_Java_Exception Handling - Fatal编程技术网

Java 无法将use def异常转换为可丢弃错误 公共类OdeException扩展异常{ 双赤字; Odexception(字符串消息,双定义){ 超级(味精); 这个.赤字=def; } } 公共作废撤销(双倍金额)引发异常{ 如果(amt

Java 无法将use def异常转换为可丢弃错误 公共类OdeException扩展异常{ 双赤字; Odexception(字符串消息,双定义){ 超级(味精); 这个.赤字=def; } } 公共作废撤销(双倍金额)引发异常{ 如果(amt,java,exception-handling,Java,Exception Handling,这就是你想要的,对吗 public class Odexception extends Exception { double deficit; Odexception(String msg,double def) { super(msg); this.deficit=def; } } public void withdraw(double amt) throws odexception { if(amt<

这就是你想要的,对吗

public class Odexception extends Exception {
     double deficit;
     Odexception(String msg,double def) {
         super(msg);
         this.deficit=def;
     }
}


public   void withdraw(double amt)  throws odexception {
     if(amt<=balance) {
         balance=balance-amt;
     } else {
          throw new Odexception("Insufficient balance",amt-balance);
     }
}

public static void main(string ar[]) {
     try{
        c[0].acc[0].withdraw(2000);
     } catch(Odexception  e) {
        System.out.println(e.getMessage());
     }
}
类OdeException扩展异常{ 双赤字; Odexception(字符串消息,双定义){ 超级(味精); 这个.赤字=def; } } 公共类自定义异常{ 双平衡; 公共客户例外(双倍余额) { 这个平衡=平衡; } 公共作废撤销(双倍金额)引发异常{
if(amt
if(question.indexOf(“?”)<0)System.exit(1);
你的问题不是很清楚,你能说你想要实现什么吗???@M.Sharma想打印消息,当amt>bal作为inuff balance使用Exception时。我希望这两个代码段来自不同的类,因为我看不到封装main()和draw()的类。您还面临什么问题?@Mustafasabir在编译过程中显示OdeException不能被说服为可丢弃
class Odexception extends Exception{
    double deficit;
    Odexception(String msg,double def) {
        super(msg);
        this.deficit=def;
    }
}

public class CustomException {
    double balance;
    public CustomException(double balance)
    {
        this.balance = balance;
    }

    public void withdraw(double amt) throws Odexception {
        if (amt <= balance) {
            {
                balance = balance - amt;
                System.out.println("Withdrawn : "+amt+"\nCurrent Balance is :"+balance);
            }
        } else {
            throw new Odexception("Insufficient balance", amt - balance);
        }
    }

    public static void main(String ar[]) {
        try {
            new CustomException(1000).withdraw(5000);
        } catch (Odexception e) {
            System.out.println(e.getMessage());
        }
    }
}