Why is “throws Exception” necessary when calling a function?

后端 未结 8 1766
借酒劲吻你
借酒劲吻你 2020-11-29 15:37
class throwseg1
{
    void show() throws Exception
    {
        throw new Exception(\"my.own.Exception\");
    }

    void show2() throws Exception  // Why throws i         


        
8条回答
  •  栀梦
    栀梦 (楼主)
    2020-11-29 15:48

    Exception is a checked exception class. Therefore, any code that calls a method that declares that it throws Exception must handle or declare it.

提交回复
热议问题