What should a JavaScript constructor return if it fails?

It is probably best to throw an exception to notify the caller that the initialization failed and to take appropriate action.

Return codes are fine, but for the most part there is no motivation for the caller to implement the checks on the return code.

My advice is to break hard and break soon. This will make contract violations very evident during testing.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)