Chapter Review

13.6. Chapter Review#

  1. What is the difference between a compile-time error and a runtime exception? Give an example of each.

  2. What are the three blocks in C# exception handling? Describe when each one executes.

  3. Why is it bad practice to catch Exception as the base type for all error handling? What should you do instead?

  4. What happens if an exception is thrown inside a finally block?

  5. Write a short code snippet that reads a number from the user and handles the case where the input is not a valid integer using int.TryParse rather than a try/catch. When is TryParse preferable to exception handling?

  6. What is the difference between throw and throw ex when re-throwing an exception? Which preserves the original stack trace?

  7. Describe the Red-Green-Refactor cycle in TDD. What does each color represent?

  8. What is the role of [TestClass] and [TestMethod] attributes in MSTest?

  9. In the BasicMath example, the Multiply method used + instead of *. Which test caught the bug, and what did Assert.AreEqual report?

  10. What is the difference between a unit test and an integration test?