Constructors shouldn't throw

I mean this is nothing new but it bears repeating.

Constructors should not throw exceptions. Nor should they do any asynchronous stuff, or really, perform any side effects at all.

But my Date constructor needs to parse a string!

Okay I’m not in the business of writing Date libraries, but still, if you need to parse a string, write a parser. And then write a factory method Date.parse(string) that uses that parser and calls a private constructor.

But my Database constructor needs to connect to the database!

Hell it does. Turn your Database class into a state machine with an uninitialized and a connected state. Then have a Database.connect() method that transitions the state from uninitialized to connected. Your unit tests will love it.