JavaScript Error Handling Essentials Quiz

  1. Understanding the try Block

    Which block is used in JavaScript to wrap code that may cause an error?

    1. monitor
    2. catcher
    3. trap
    4. caught
    5. try
  2. Correct Catch Block Syntax

    What is the correct way to start a catch block after a try block in JavaScript?

    1. catching(error)
    2. catch: error
    3. catch(error)
    4. catcher(error)
    5. catch error
  3. Purpose of finally Block

    Which JavaScript block is always executed after try and catch, regardless of whether an error occurred?

    1. complete
    2. finish
    3. done
    4. end
    5. finally
  4. Using throw Statement

    Which statement is used in JavaScript to manually trigger an error?

    1. raise
    2. rise
    3. throw
    4. emit
    5. error
  5. Error Object Basics

    What does the built-in Error object in JavaScript represent?

    1. A log entry
    2. An exception that is thrown
    3. A successful result
    4. A function callback
    5. A warning message
  6. Accessing Error Message

    After an error is caught, which property of the error object contains the error message?

    1. msg
    2. reason
    3. message
    4. detail
    5. description
  7. Handling Errors Gracefully

    What is one main advantage of using try/catch in JavaScript?

    1. It disables error logging
    2. It automatically fixes syntax errors
    3. It allows handling errors without stopping script execution
    4. It slows down the program intentionally
    5. It checks for memory leaks
  8. Custom Error Throwing Example

    What happens when the following code is executed? throw new Error('Invalid input');

    1. A warning is displayed but code continues
    2. An error is created and thrown with the message 'Invalid input'
    3. The code is ignored and nothing happens
    4. The error is silently logged
    5. JavaScript restarts the program
  9. Catching Specific Error Types

    In JavaScript, which error object is specifically thrown for references to undefined variables?

    1. ValueError
    2. TypeError
    3. ErrorRef
    4. ReferenceError
    5. SyntaxError
  10. Understanding Error Propagation

    If an error is not caught inside a try/catch block, what typically happens in JavaScript?

    1. The script pauses and resumes
    2. The error is fixed automatically
    3. A custom handler always runs
    4. The error propagates up and may stop script execution
    5. The code jumps to the start
  11. Order of Execution

    Given a try/catch/finally structure, which block is always executed regardless of errors?

    1. lastly
    2. finally
    3. finish
    4. always
    5. done
  12. Creating Custom Errors

    How do you create a custom error type in JavaScript?

    1. By extending the Error class
    2. By defining an error in catch
    3. By setting error.custom = true
    4. By calling createError()
    5. By using 'makeError'
  13. Handling Syntax Errors

    Can a try/catch statement catch syntax errors that occur during JavaScript parsing?

    1. No, syntax errors occur before try/catch runs
    2. Yes, but only with custom errors
    3. Only with the 'catchAll' method
    4. Only if using finally
    5. Yes, always
  14. Accessing Error Name

    Which property of the error object in JavaScript gives the type of error?

    1. name
    2. class
    3. category
    4. error
    5. type
  15. Error Handling in Asynchronous Code

    When using Promises, which method is typically used to handle errors instead of try/catch?

    1. catcher()
    2. trap()
    3. error()
    4. catch()
    5. throw()