What's the best technique for exiting from a constructor on an error condition in C++

后端 未结 8 845
北荒
北荒 2020-12-14 08:21

What\'s the best technique for exiting from a constructor on an error condition in C++? In particular, this is an error opening a file.

Thanks for the responses. I\'

8条回答
  •  独厮守ぢ
    2020-12-14 08:39

    In general, you should throw an exception. The alternative is to have some half-correctly constructed object which the user has to test somehow, which they will inevitably fail to do.

提交回复
热议问题