Exception Handling
Handle errors gracefully with try, catch, and throw. Use exceptions for error recovery.
Lessons
1. Intro
Error handling with exceptions
2. What Are Exceptions?
Separating errors from logic
3. Why Exceptions?
Error codes get ignored
4. The try Block
Marking risky operations
5. The throw Statement
Triggering exception handling
6. Quiz: Exception handling
Exception handling
7. The catch Block
Responding to exceptions
8. Basic try-catch Example
First exception handler
9. Quiz: Exception handling
Exception handling
10. Quiz: try-catch Basics
Knowledge check
11. Catching by Value vs Reference
Avoiding object slicing
12. Multiple catch Blocks
Handling different error types
13. Quiz: Variable alias
Variable alias
14. Catch-All Handler (catch(...))
Unknown exception types
15. Standard Exception Classes
Built-in error types
16. Quiz: Error signaling
Error signaling
17. std::exception Base Class
Top of exception hierarchy
18. std::runtime_error and std::logic_error
Two main exception categories
19. Quiz: Error signaling
Error signaling
20. Quiz: Exception Categories
Knowledge check
21. std::out_of_range, std::invalid_argument
Specific error types
22. Creating Custom Exceptions
Domain-specific error types
23. Quiz: Error signaling
Error signaling
24. Inheriting from std::exception
Proper exception derivation
25. The what Method
Getting error descriptions
26. Quiz: Error signaling
Error signaling
27. Rethrowing Exceptions
Passing errors upward
28. Exception Propagation
How exceptions travel upward
29. Quiz: Error signaling
Error signaling
30. Quiz: Stack Unwinding
Knowledge check
31. noexcept Specifier
Functions that never throw
32. When to Use Exceptions
Choosing error mechanisms
33. Quiz: Error signaling
Error signaling
34. Exceptions vs Error Codes
Comparing error strategies
35. Quiz: When to Use Exceptions
Knowledge check
36. Exception Safety Basics
Guarantees about error states
37. RAII and Exceptions
Automatic resource cleanup
38. Quiz: Error signaling
Error signaling
39. Quiz: Exception Safety
Knowledge check
40. Practice Problems
Apply exception handling
41. Section 18 Recap
Exception handling review
42. Problem - Safe Division
Error handling fundamentals
43. Safe Division - The Idea
Exception benefits
44. Safe Division - Algorithm
Implementation approach
45. Quiz: Integer division
Integer division
46. Safe Division - Implementation
Pseudocode solution
47. Lessons from Safe Division
summary
48. Problem - Input Validator
Catching different errors
49. Input Validator - The Idea
Catching by type
50. Input Validator - Algorithm
Implementation approach
51. Quiz: Error signaling
Error signaling
52. Input Validator - Implementation
Pseudocode solution
53. Lessons from Input Validator
summary
54. Section Recap
What we learned