JavaScript Error Handling Deep Dive Quiz

Assess your understanding of advanced error handling concepts in JavaScript, including control flow with try/catch/finally, custom errors, stack traces, and the use of the throw statement.

  1. Catching Specific Error Types

    Given the code `try { JSON.parse(undefined); } catch(e) { if(e instanceof SyntaxError) console.log('Syntax'); }`, what will be logged to the console?

    1. Syntax
    2. Type
    3. Error
    4. Nothing
    5. Reference
  2. Custom Error Throwing

    Which is the correct way to throw an error with the message 'Invalid Data' in JavaScript?

    1. raise Error('Invalid Data');
    2. catch Error('Invalid Data');
    3. except('Invalid Data');
    4. throw Error('Invalid Data');
    5. throw.error('Invalid Data');
  3. try/finally Control Flow

    If a return statement is encountered in the try block, will the finally block still execute?

    1. Yes, finally always executes
    2. Only if catch is present
    3. Only if no error is thrown
    4. Only if return is conditional
    5. No, finally will be skipped
  4. Implicit Error Propagation

    What happens if an error is thrown inside the try block and there is no corresponding catch block?

    1. The error variable is set to undefined
    2. The script is silently ignored
    3. finally block prevents the error
    4. The error propagates up to the next higher scope
    5. A warning is logged but code continues
  5. Error Object Properties

    Which property of the Error object contains a description of the error?

    1. info
    2. detail
    3. code
    4. message
    5. desc
  6. Stack Trace Access

    After catching an error object 'e', what property can you access to retrieve the stack trace as a string?

    1. e.line
    2. e.cause
    3. e.tracing
    4. e.tracer
    5. e.stack
  7. Rethrowing Errors

    What is the effect of rethrowing an error from within a catch block using `throw e;`?

    1. It ignores the caught error
    2. It restarts the current block
    3. It propagates the error up to outer try/catch blocks
    4. It logs the error and terminates the program
    5. It creates a new error object
  8. finally and Return

    If both try and finally blocks contain return statements, which value will be returned from the function?

    1. The value from the try block
    2. The value from the finally block
    3. An error is thrown
    4. undefined
    5. The value from the catch block, if present
  9. Error Subclassing

    Which is the correct way to define a custom error class named 'ValidationError'?

    1. Error extends class ValidationError {}
    2. class ValidationError extends Error {}
    3. function ValidationError() extends Error {}
    4. class ValidationError implements Error {}
    5. object ValidationError inherits Error {}
  10. throw Statement Restrictions

    What types of values can you throw using the throw statement in JavaScript?

    1. Any JavaScript expression, including strings, numbers, or objects
    2. Primitive types only
    3. Only instances of Error and its subclasses
    4. Only error codes (numbers)
    5. Only string values
  11. Erroneous try/catch Syntax

    What is the result of attempting to use a try block without a corresponding catch or finally block?

    1. try acts as a new scope
    2. The try block defaults to a catch
    3. No error, but errors can’t be caught
    4. The code runs but try is ignored
    5. A syntax error occurs
  12. Error Object Creation Behavior

    What does `throw new Error('Oops');` actually do in JavaScript execution?

    1. Halts current execution and searches for catch/finally
    2. Resets all variables
    3. Ignores the error if uncaught
    4. Logs a warning but continues
    5. Only displays an alert
  13. catch Parameter Scope

    Where is the variable declared as the catch parameter accessible in JavaScript?

    1. Within try, catch, and finally
    2. Within the entire function
    3. Throughout the script
    4. Globally
    5. Only within the catch block
  14. Misleading Catch Block Behaviors

    Which of the following does NOT cause the catch block to execute?

    1. A manually thrown string in try
    2. A return statement in the try block
    3. A runtime exception in the try block
    4. A thrown error in the try block
    5. A thrown custom Error object
  15. Inheritance of Error Properties

    If you create `class CustomError extends Error {}` and throw an instance, which of these properties are inherited by default?

    1. signal and nameOnly
    2. reason and location
    3. cause and trace
    4. message and stack
    5. code and errno