Skip to content
Learn Netverks

Lesson

Step 16/36 44% through track

errors-async

Errors in async code

Last reviewed May 28, 2026 Content v20260528
Track mode
nodejs_server
Means
Node sandbox
Reading
~1 min
Level
intermediate

This lesson

This lesson teaches Errors in async code: the syntax, APIs, and habits you need before advancing in Node.js.

Non-blocking APIs are idiomatic Node—callback hell and unhandled rejections still fail production services.

You will apply Errors in async code in contexts like: REST/GraphQL APIs, BFF layers, CLIs, webhooks, and real-time services (with WebSockets).

Run JavaScript on the Node runner when configured—never mix arbitrary shell commands in lessons.

When you can explain the previous lesson's ideas without copying starter code.

Async errors surface differently: thrown errors inside callbacks need explicit handling; promise rejections need .catch; async/await uses try/catch. Uncaught errors crash or log via process events.

Patterns

  • Sync — try/catch around code that throws
  • Promises.catch or try/catch with await
  • Express — async route errors forwarded with next(err) or centralized error middleware

Custom errors

class AppError extends Error {
  constructor(message, status = 500) {
    super(message);
    this.status = status;
  }
}

Important interview questions and answers

  1. Q: unhandledRejection vs uncaughtException?
    A: Rejection is an unhandled failed Promise; exception is a sync throw outside try/catch—both should be logged; process may exit depending on policy.
  2. Q: Should you expose stack traces to API clients?
    A: No in production—log internally, return generic message and correlation id.

Self-check

  1. How do you catch a failed await?
  2. Why create custom error classes with status codes?

Interview tip Lesson completion confidence

Can you explain this lesson in 30 seconds without reading notes?

Not saved yet.

Playground

Runs on the configured server runner (dev: npm run runner with LEARNING_RUNNER_ENABLED=true). Output appears below the editor.

Check yourself

Multiple choice — immediate feedback.

Discussion

Past discussion is visible to everyone. Only logged-in users can post comments and replies.

Starter discussion topics

  • try/catch with await?
  • Central error middleware?

Sign up or log in to post comments and sync lesson progress across devices.

No discussion yet. Be the first to ask a question.

Jump