Sparround

Error handling

Errors are raised with throw, caught with try/catch, and finally always runs (for cleanup).

In async code, an awaited rejection lands in catch — the standard way to handle async errors. The error of a non-awaited Promise does NOT land in try/catch!

Throwing your own: throw new Error('Could not create user: ' + response.status) — make messages specific, they ease debugging.

Use try/catch sparingly in test code: swallowing an assertion error in catch and letting the test stay "green" is the most dangerous anti-pattern. try/catch belongs only to (1) expected alternative flows and (2) cleanup — assertions should be free to "explode".

📚 Sources and documentation