Pro Coder Quiz

CapDev Harbinger Group

ProCoder Quiz of the Month - May 2024

Top 3 Winners:

Vishal Khatal, Rishabh Mourya and Ganesh Kale

Congratulations!!

Quiz Questions and answers are below:

 

1. What is the purpose of the ‘finally’ block?

  1. To catch exceptions
  2. To execute code after a try block, regardless of whether an exception was thrown
  3. To skip code execution
  4. To throw an exception

Correct Answer: Option 2

 

2. What is exception chaining?

  1. Linking multiple exceptions together to form a hierarchy
  2. Catching exceptions in multiple try blocks
  3. Wrapping one exception inside another to preserve the original exception
  4. Using multiple catch blocks for one try block

Correct Answer: Option 3

 

3. Chain of Responsibility pattern is a pattern where one object takes all responsibilities?

  1. True
  2. False

Correct Answer: Option 2

 

4. Which of the following statements is not a recommended practice?

  1. Catching only exceptions you can handle
  2. Logging detailed error information
  3. Using exceptions for control flow
  4. Rethrowing exceptions to higher levels when necessary

Correct Answer: Option 3

 

5. In a multithreaded application, what should you do if you need to handle exceptions in a thread-safe manner?

  1. Handle exceptions outside the threads
  2. Handle exceptions inside each thread and use synchronization for shared resources
  3. Ignore exceptions to improve performance
  4. Use the sleep method to manage exceptions

Correct Answer: Option 2

 

6. What happens if an exception is not caught in a thread?

  1. The application continues normally
  2. The thread stops execution and the exception is ignored
  3. The exception is propagated to the main thread automatically
  4. The application may terminate if the exception is unhandled

Correct Answer: Option 4

 

7. What should you do when creating a custom exception class?

  1. Ignore the base exception class
  2. Only implement the default constructor
  3. Implement constructors that support message and inner exception parameters
  4. Override the ToString method only

Correct Answer: Option 3

 

8. Which of the following statements best describes the purpose of Retry Pattern?

  1. To retry a failed operation a specified number of times before giving up
  2. To ignore exceptions and continue execution
  3. To immediately throw an exception when an error occurs
  4. To log exceptions without retrying

Correct Answer: Option 1

 

9. In the Circuit Breaker pattern, what happens when the circuit breaker is in the "Open" state?

  1. Requests are allowed to proceed
  2. Requests are automatically retried
  3. Requests are short-circuited and fail immediately
  4. The system logs the request without processing it

Correct Answer: Option 3

 

10. What is the primary purpose of the Fallback pattern in exception handling?

  1. To retry an operation
  2. To execute an alternative logic when the primary logic fails
  3. To log the exception and terminate the program
  4. To rethrow the exception to the caller

Correct Answer: Option 2

11. Which pattern does the following statement describe: It allows multiple handlers to process an exception in sequence until one handles it.

  1. Fallback pattern
  2. Retry pattern
  3. Circuit breaker pattern
  4. Chain of responsibility pattern

Correct Answer: Option 4

 

12. The Retry pattern often includes an exponential backoff strategy. What does exponential backoff mean?

  1. Retrying immediately after a failure
  2. Increasing the delay between retries exponentially with each failure
  3. Reducing the delay between retries exponentially with each failure
  4. Retrying a fixed number of times without delay

Correct Answer: Option 2

 

13. What is the benefit of using exception assertions in unit tests?

  1. They ensure the application runs faster
  2. They make code easier to read
  3. They improve code indentation
  4. They confirm that code behaves as expected when an error occurs

Correct Answer: Option 4

 

14. When testing for exceptions, what is a common practice to verify exception properties?

  1. Catching the exception and asserting its properties
  2. Ignoring the exception properties
  3. Only testing the exception type
  4. Only testing if the exception is thrown

Correct Answer: Option 1

  

15. What type of exception should be thrown to indicate an invalid parameter passed to a method?

  1. NullReferenceException
  2. IndexOutOfRangeException
  3. ArgumentException
  4. IOException

Correct Answer: Option 3


Last modified: Tuesday, 28 May 2024, 4:41 PM