为什么我收到未报告的异常

为什么我收到未报告的异常

本文介绍了为什么我收到未报告的异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请问为什么第13行中的错误作为未报告的异常而出现,必须被PR声明被抛出

  class Demo {
public static void main(String args []){
try {
int x = 43/0;
} catch(ArithmeticException ob){
throw ob;
}

试试{
int x = 43/0;
} catch(Exception ob){
throw ob;
}
Exception ob = new Exception();
throw ob;
//第13行未报告的异常Exception;必须被捕获或声明为抛出
}
}


解决方案

您需要向抛出异常的方法以及之前调用该方法的所有方法添加抛出 b $ b

can you please why error comes in line 13 as unreported exception ,must be caught pr declared to be thrown

class Demo {
    public static void main(String args[]) {
        try {
            int x = 43 / 0;
        } catch (ArithmeticException ob) {
            throw ob;
        }

        try {
            int x = 43 / 0;
        } catch (Exception ob) {
            throw ob;
        }
        Exception ob = new Exception();
        throw ob;
        // Line 13 unreported exception Exception; must be caught or declared to be thrown
    }
}
解决方案

You need to add a throws to the method that throws exceptions as mentioned before as well as all the methods that call that method

这篇关于为什么我收到未报告的异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 23:46