Skip to content

Error Handling

Medium — good to knowGeneral Dev

ELI5 — The Vibe Check

Error handling is the art of planning for things to go wrong and dealing with them gracefully instead of letting everything catch fire. Good error handling means your app shows a friendly message instead of crashing. Bad error handling means users see raw error dumps or, worse, a white blank screen.

Real Talk

Error handling encompasses all strategies for detecting, catching, and recovering from errors at runtime. It includes try/catch blocks, error boundary components (React), promise rejection handlers, global error handlers (process.on('uncaughtException')), input validation, and meaningful error messages for debugging. Good error handling distinguishes between expected errors (validation failures) and unexpected errors (bugs).

Show Me The Code

// Layered error handling in an Express API:
app.get('/user/:id', async (req, res) => {
  try {
    const user = await db.findUser(req.params.id);
    if (!user) return res.status(404).json({ error: 'Not found' });
    res.json(user);
  } catch (err) {
    console.error(err); // log for devs
    res.status(500).json({ error: 'Internal server error' }); // safe for users
  }
});

When You'll Hear This

"The error handling needs work — it's showing raw stack traces to users." / "Add proper error handling before we ship this."

Made with passive-aggressive love by manoga.digital. Powered by Claude.