Course contentsShow
← JavaScript
Lesson 1361 of 2,72330. Async/AwaitFree lesson

Uncaught Errors in Async Functions

Learn what happens when an async function error is not caught and how it becomes an unhandled rejection.

Uncaught Errors in Async Functions

You'll learn what happens when an async function throws an error that nobody catches—and why it matters.

The Unhandled Rejection Problem

When an async function throws an error (or awaits a rejected Promise) and there's no try/catch block inside the function and no .catch() handler attached when calling it, that error doesn't crash your program immediately. Instead, it becomes an unhandled rejection.

Think of it like throwing a ball in an empty room—nobody's there to catch it, so it just bounces around until someone notices the noise.

What Actually Happens

async function riskyOperation() {
  throw new Error('Something went wrong!');
  // No try/catch here
}

// Called without .catch()
riskyOperation();

console.log('This still runs!');

In this example:

  1. The error is thrown inside riskyOperation
  2. Since it's an async function, the error becomes a rejected Promise
  3. No .catch() handler is attached, so the rejection is unhandled
  4. The script continues executing—console.log still runs!
  5. The JavaScript environment logs an "Unhandled Promise Rejection" warning

Why This Is Dangerous

Unhandled rejections can hide bugs in your code. Your application might appear to work while silently failing in the background. In Node.js, unhandled rejections can even terminate the entire process in stricter configurations.

The Fix

Always handle errors from async functions:

riskyOperation().catch(err => {
  console.error('Caught:', err.message);
});

Key Takeaway: An uncaught error in an async function becomes an unhandled Promise rejection, which continues executing but logs warnings—always attach .catch() or use try/catch to prevent silent failures.