Constructors Shouldn't Throw

2 points | by jcbhmr 2 hours ago

1 comments

  • AnimalMuppet 38 minutes ago

    > Because the semantics of a constructor is to bring an object into a valid state and you don’t expect it to perform any functionality.

    No, I expect it to perform the functionality of bringing the object into a valid state - whatever functionality that takes. And if it can't, then throwing is the next option, because it's preferable to having an object in an invalid state.