Can I use throws in constructor?

前端 未结 12 2220
迷失自我
迷失自我 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:18

    Generally it is a bad idea to do heavy lifting in constructors: in many languages, you'll be restricted anyhow in what can be done about exceptions during construction.

提交回复
热议问题