Interview frequency: …
Short answer
Fail-Fast means detecting problems as soon as they occur and throwing a clear exception at the earliest point. Avoid empty try-catch blocks that swallow errors and hide failures.
Explanation
Swallowing an exception with catch (e) {} without logging or handling it is a serious coding mistake: the system continues in a corrupted or inconsistent state and may fail obscurely elsewhere minutes later. Good practices are: (1) validate inputs at the start of the function and throw a precise exception immediately; (2) create meaningful domain-specific exceptions; and (3) handle errors at the appropriate high level, such as a Global Error Handler.
Code example
// Fatal error (swallowing the exception):
try { saveTransaction(); } catch (err) { /* Complete silence */ }
// True (Fail-Fast):
if (amount <= 0) throw new InvalidTransactionAmountException(amount);Common mistakes
- Using Exceptions for ordinary program flow control instead of handling genuinely exceptional cases.