Can I use throws in constructor?

前端 未结 12 2219
迷失自我
迷失自我 2021-01-13 21:03

I have to initialize file objects inside the constructor and for handling the exception, is it efficient using throws or should I go for try/

12条回答
  •  [愿得一人]
    2021-01-13 21:31

    Of course, it's actually used a lot in Java. For example,

    public FileInputStream(String name)
                    throws FileNotFoundException
    

提交回复
热议问题