• Full Stack Dev CourseExplore
  • Error Handling in Next.js

    Last Updated :
    Discuss
    Comments

    Question 1

    What is the purpose of a custom 404 page in Next.js?

    • A

      To handle API errors globally

    • B

      To provide a user-friendly message when a URL is not found

    • C

      To log server errors for debugging

    • D

      To define React error boundaries

    Question 2

    Where should you place a custom 404 page file in a Next.js project?

    • A

      /pages/404.js

    • B

      /components/404.js

    • C

      /utils/404.js

    • D

      /api/404.js

    Question 3

    In Next.js API routes, why do we use try/catch blocks?

    • A

      To create a 404 page

    • B

      To render the homepage

    • C

      To optimize performance

    • D

      To prevent server crashes and handle errors gracefully

    Question 4

    What status code should be returned when a method is not allowed in a Next.js API route?

    • A

      404

    • B

      500

    • C

      405

    • D

      200

    Question 5

    What is the role of a React Error Boundary?

    • A

      To catch errors in asynchronous code like setTimeout

    • B

      To prevent the entire app from crashing due to errors in child components

    • C

      To validate API requests

    • D

      To log server-side errors

    Question 6

    Which errors cannot be caught by React Error Boundaries?

    • A

      Errors in child components during render

    • B

      Errors in lifecycle methods

    • C

      Errors in event handlers or async code

    • D

      Errors in constructors

    Question 7

    In Next.js App Router, which file handles route-specific errors with a fallback UI?

    • A

      not-found.js

    • B

      error.js

    • C

      global-error.js

    • D

      404.js

    Question 8

    What does the reset() function do in a Next.js error.js or global-error.js file?

    • A

      Resets the component tree to attempt recovery

    • B

      Reloads the API route

    • C

      Navigates to the homepage

    • D

      Logs the error in the console

    Question 9

    What will happen if both counters are wrapped in the same Error Boundary in React?

    • A

      Only the counter that throws an error will stop rendering

    • B

      Both counters will crash and fallback UI will display

    • C

      The app will continue without any fallback

    • D

      React will automatically retry the counter

    Question 10

    In Next.js, which file is used specifically to display a custom "Page Not Found" message for missing routes?

    • A

      error.js

    • B

      global-error.js

    • C

      not-found.js

    • D

      pages/_app.js

    Tags:

    There are 10 questions to complete.

    Take a part in the ongoing discussion