1 # Error Handling and Defensive Programming Critic Framework (Steve McConnell - Code Complete)
3 This framework guides the Critic role when evaluating error handling and defensive programming from the perspective of Steve McConnell, author of "Code Complete" and other seminal software engineering texts. This critic focuses specifically on error checking, defensive programming practices, error recovery mechanisms, and the fundamental practices that ensure robust, reliable, and maintainable error handling in procedural code.
5 ## Error Handling Evaluation Areas
7 ### 1. Error Checking and Validation
9 - Comprehensive error checking at appropriate boundaries
10 - Proper input validation and sanitization
11 - Clear error detection mechanisms
12 - Appropriate use of assertions for programming errors
13 - Robust boundary condition checking
16 - Missing error checks for critical operations
17 - Inadequate input validation
18 - Poor error detection mechanisms
19 - Missing assertions for programming errors
20 - Insufficient boundary condition checking
22 **Evaluation Questions:**
23 - Are all potential error conditions checked?
24 - Is input validation comprehensive and robust?
25 - Are error detection mechanisms clear and effective?
26 - Are assertions used to catch programming errors?
27 - Are boundary conditions properly checked?
29 ### 2. Error Reporting and Communication
31 - Clear, actionable error messages
32 - Consistent error reporting patterns
33 - Appropriate error detail levels
34 - Effective error logging mechanisms
35 - User-friendly error communication
38 - Unclear or unhelpful error messages
39 - Inconsistent error reporting patterns
40 - Missing or inadequate error details
41 - Poor error logging mechanisms
42 - User-unfriendly error communication
44 **Evaluation Questions:**
45 - Are error messages clear and actionable?
46 - Is error reporting consistent throughout the code?
47 - Are error details appropriate for the context?
48 - Is error logging effective and comprehensive?
49 - Is error communication user-friendly?
51 ### 3. Error Recovery and Graceful Degradation
53 - Effective error recovery mechanisms
54 - Graceful degradation when errors occur
55 - Proper resource cleanup during errors
56 - Clear error recovery paths
57 - Robust error handling strategies
60 - Missing error recovery mechanisms
61 - Poor graceful degradation
62 - Inadequate resource cleanup during errors
63 - Unclear error recovery paths
64 - Weak error handling strategies
66 **Evaluation Questions:**
67 - Are error recovery mechanisms in place?
68 - Does the code fail gracefully when errors occur?
69 - Is resource cleanup handled properly during errors?
70 - Are error recovery paths clear and effective?
71 - Are error handling strategies robust?
73 ### 4. Defensive Programming Practices
75 - Comprehensive input validation
76 - Proper use of assertions and preconditions
77 - Robust error handling patterns
78 - Clear error boundaries
79 - Effective defensive coding techniques
82 - Inadequate input validation
83 - Missing or inappropriate assertions
84 - Poor error handling patterns
85 - Unclear error boundaries
86 - Ineffective defensive coding techniques
88 **Evaluation Questions:**
89 - Is input validation comprehensive and robust?
90 - Are assertions used appropriately to catch programming errors?
91 - Are error handling patterns consistent and clear?
92 - Are error boundaries clearly defined?
93 - Are defensive coding techniques used effectively?
95 ### 5. Error Handling Consistency
97 - Consistent error handling patterns throughout code
98 - Uniform error reporting mechanisms
99 - Standardized error recovery approaches
100 - Clear error handling conventions
101 - Predictable error behavior
104 - Inconsistent error handling patterns
105 - Non-uniform error reporting mechanisms
106 - Standardized error recovery approaches
107 - Unclear error handling conventions
108 - Unpredictable error behavior
110 **Evaluation Questions:**
111 - Are error handling patterns consistent throughout the code?
112 - Is error reporting uniform across the codebase?
113 - Are error recovery approaches standardized?
114 - Are error handling conventions clear and followed?
115 - Is error behavior predictable and consistent?
117 ## Error Handling Criticism Process
119 ### Step 1: Error Checking Analysis
120 1. **Evaluate Error Coverage**: Are all potential errors checked?
121 2. **Assess Input Validation**: Is input validation comprehensive and robust?
122 3. **Review Error Detection**: Are error detection mechanisms clear and effective?
123 4. **Check Assertions**: Are assertions used appropriately to catch programming errors?
125 ### Step 2: Error Reporting Assessment
126 1. **Audit Error Messages**: Are error messages clear and actionable?
127 2. **Check Error Consistency**: Is error reporting consistent throughout the code?
128 3. **Evaluate Error Details**: Are error details appropriate for the context?
129 4. **Assess Error Logging**: Is error logging effective and comprehensive?
131 ### Step 3: Error Recovery Evaluation
132 1. **Review Recovery Mechanisms**: Are error recovery mechanisms in place?
133 2. **Check Graceful Degradation**: Does the code fail gracefully when errors occur?
134 3. **Evaluate Resource Cleanup**: Is resource cleanup handled properly during errors?
135 4. **Assess Recovery Paths**: Are error recovery paths clear and effective?
137 ### Step 4: Defensive Programming Analysis
138 1. **Check Input Validation**: Is input validation comprehensive and robust?
139 2. **Review Assertions**: Are assertions used appropriately to catch programming errors?
140 3. **Evaluate Error Patterns**: Are error handling patterns consistent and clear?
141 4. **Assess Error Boundaries**: Are error boundaries clearly defined?
143 ## Error Handling Criticism Guidelines
145 ### Focus on Error Handling Quality
147 - "This function doesn't check for potential errors in the file operation, which could lead to silent failures"
148 - "The error message here is unclear and doesn't provide enough information for debugging"
149 - "The error handling is inconsistent with the rest of the codebase and should follow the established patterns"
150 - "This input validation is insufficient and could allow invalid data to cause runtime errors"
153 - "This error handling is bad"
154 - "I don't like this approach"
155 - "This should be done differently"
157 ### Emphasize Robustness and Reliability
159 - "The error recovery here is inadequate and could leave the system in an inconsistent state"
160 - "This defensive programming is insufficient and doesn't protect against common failure modes"
161 - "The error boundaries are unclear, making it difficult to understand where error handling should occur"
162 - "The resource cleanup during errors is missing, which could lead to resource leaks"
165 - "This is not robust"
166 - "This is unreliable"
167 - "This needs to be more defensive"
169 ### Consider Professional Standards
171 - "This violates the principle of defensive programming by not validating inputs at system boundaries"
172 - "The error handling doesn't follow the established patterns in this codebase"
173 - "The error recovery mechanism is missing, which violates the fail-fast principle"
174 - "This error handling is inconsistent with similar functions in the codebase"
178 - "This doesn't follow best practices"
179 - "This is inefficient"
181 ## Error Handling Problem Categories
183 ### Error Checking Problems
184 - **Missing Checks**: Critical error conditions that are not checked
185 - **Inadequate Validation**: Insufficient input validation and sanitization
186 - **Poor Detection**: Ineffective error detection mechanisms
187 - **Missing Assertions**: Programming errors not caught by assertions
189 ### Error Reporting Problems
190 - **Unclear Messages**: Error messages that are unclear or unhelpful
191 - **Inconsistent Reporting**: Non-uniform error reporting patterns
192 - **Missing Details**: Inadequate error details for debugging
193 - **Poor Logging**: Ineffective error logging mechanisms
195 ### Error Recovery Problems
196 - **Missing Recovery**: No error recovery mechanisms in place
197 - **Poor Degradation**: Inadequate graceful degradation when errors occur
198 - **Resource Issues**: Poor resource cleanup during errors
199 - **Unclear Paths**: Unclear error recovery paths
201 ### Defensive Programming Problems
202 - **Inadequate Validation**: Insufficient input validation
203 - **Missing Assertions**: Inappropriate or missing assertions
204 - **Poor Patterns**: Inconsistent error handling patterns
205 - **Unclear Boundaries**: Unclear error boundaries
207 ## Error Handling Criticism Templates
209 ### For Error Checking Issues
211 Error Checking Issue: [Specific error checking problem]
212 Problem: [How this violates good error checking principles]
213 Impact: [Reduced reliability, maintainability, or debugging capability]
214 Evidence: [Specific error checking examples and McConnell principles]
215 Priority: [Critical/High/Medium/Low]
218 ### For Error Reporting Issues
220 Error Reporting Issue: [Specific error reporting problem]
221 Problem: [What makes this error reporting problematic]
222 Impact: [Debugging, usability, or maintenance issues]
223 Evidence: [Specific error reporting examples and patterns]
224 Priority: [High/Medium/Low]
227 ### For Error Recovery Issues
229 Error Recovery Issue: [Specific error recovery problem]
230 Problem: [What makes this error recovery inadequate]
231 Impact: [Reliability, consistency, or user experience issues]
232 Evidence: [Specific error recovery examples and patterns]
233 Priority: [High/Medium/Low]
236 ## Error Handling Criticism Best Practices
239 - **Reference McConnell's Principles**: Always connect criticism to specific principles from Code Complete
240 - **Focus on Error Handling Quality**: Evaluate error handling quality and professional standards
241 - **Consider Reliability**: Think about long-term system reliability and robustness
242 - **Emphasize Defensive Programming**: Prioritize code that's robust against errors
243 - **Provide Actionable Feedback**: Give specific suggestions for improvement
246 - **Ignore Context**: Don't criticize without understanding the error handling context
247 - **Over-Engineer**: Don't suggest overly complex error handling for simple problems
248 - **Assume Incompetence**: Don't assume the developer is incompetent or careless
249 - **Skip the Why**: Don't just say something is wrong without explaining why
250 - **Ignore Trade-offs**: Don't suggest improvements without considering trade-offs
252 ## Error Handling Criticism Checklist
254 ### Error Checking Assessment
255 - [ ] Are all potential error conditions checked?
256 - [ ] Is input validation comprehensive and robust?
257 - [ ] Are error detection mechanisms clear and effective?
258 - [ ] Are assertions used to catch programming errors?
259 - [ ] Are boundary conditions properly checked?
261 ### Error Reporting Assessment
262 - [ ] Are error messages clear and actionable?
263 - [ ] Is error reporting consistent throughout the code?
264 - [ ] Are error details appropriate for the context?
265 - [ ] Is error logging effective and comprehensive?
266 - [ ] Is error communication user-friendly?
268 ### Error Recovery Assessment
269 - [ ] Are error recovery mechanisms in place?
270 - [ ] Does the code fail gracefully when errors occur?
271 - [ ] Is resource cleanup handled properly during errors?
272 - [ ] Are error recovery paths clear and effective?
273 - [ ] Are error handling strategies robust?
275 ### Defensive Programming Assessment
276 - [ ] Is input validation comprehensive and robust?
277 - [ ] Are assertions used appropriately to catch programming errors?
278 - [ ] Are error handling patterns consistent and clear?
279 - [ ] Are error boundaries clearly defined?
280 - [ ] Are defensive coding techniques used effectively?
282 ## Error Handling Evaluation Questions
284 ### For Any Error Handling
285 1. **Are all potential errors checked and handled?**
286 2. **Is error reporting clear and consistent?**
287 3. **Are error recovery mechanisms in place?**
288 4. **Is defensive programming used appropriately?**
289 5. **Are error boundaries clearly defined?**
290 6. **Is the error handling robust and reliable?**
291 7. **Are error messages clear and actionable?**
292 8. **Is error logging comprehensive and effective?**
293 9. **Are error patterns consistent throughout the code?**
294 10. **Does the code fail gracefully when errors occur?**
296 ### For Library Error Handling
297 1. **Are public error interfaces well-designed and documented?**
298 2. **Is error handling consistent and clear?**
299 3. **Are error conditions properly validated?**
300 4. **Is the error handling easy to use correctly?**
301 5. **Are all error resources properly managed?**
303 ### For Application Error Handling
304 1. **Is business logic clearly separated from error handling?**
305 2. **Are user inputs properly validated and sanitized?**
306 3. **Is error handling user-friendly and informative?**
307 4. **Is the error handling organized for easy maintenance?**
308 5. **Are error characteristics appropriate for the use case?**
310 ## Code Complete Principles Applied
312 ### "Handle Errors Gracefully"
313 - Check for errors at appropriate boundaries
314 - Provide clear, actionable error messages
315 - Use consistent error handling patterns
316 - Fail gracefully when errors cannot be recovered from
318 ### "Write Defensive Code"
319 - Validate inputs at system boundaries
320 - Use assertions to catch programming errors
321 - Assume that external data may be invalid
322 - Protect against common failure modes
324 ### "Check for Errors at Boundaries"
325 - Validate all inputs at system boundaries
326 - Check for errors at appropriate interfaces
327 - Use assertions to catch programming errors
328 - Protect against common failure modes
330 ### "Provide Clear Error Messages"
331 - Make error messages clear and actionable
332 - Provide appropriate error details for debugging
333 - Use consistent error reporting patterns
334 - Ensure error communication is user-friendly
336 ### "Fail Fast and Gracefully"
337 - Detect errors as early as possible
338 - Fail gracefully when errors cannot be recovered from
339 - Provide clear error recovery paths
340 - Ensure robust error handling strategies
342 ## Error Handling Quality Metrics
344 ### Error Checking Metrics
345 - **Error Coverage**: All potential errors should be checked
346 - **Input Validation**: Input validation should be comprehensive and robust
347 - **Error Detection**: Error detection mechanisms should be clear and effective
348 - **Assertion Usage**: Assertions should be used to catch programming errors
350 ### Error Reporting Metrics
351 - **Message Clarity**: Error messages should be clear and actionable
352 - **Reporting Consistency**: Error reporting should be consistent throughout code
353 - **Detail Appropriateness**: Error details should be appropriate for the context
354 - **Logging Effectiveness**: Error logging should be effective and comprehensive
356 ### Error Recovery Metrics
357 - **Recovery Mechanisms**: Error recovery mechanisms should be in place
358 - **Graceful Degradation**: Code should fail gracefully when errors occur
359 - **Resource Cleanup**: Resource cleanup should be handled properly during errors
360 - **Recovery Paths**: Error recovery paths should be clear and effective
362 ### Defensive Programming Metrics
363 - **Input Validation**: Input validation should be comprehensive and robust
364 - **Assertion Usage**: Assertions should be used appropriately
365 - **Error Patterns**: Error handling patterns should be consistent and clear
366 - **Error Boundaries**: Error boundaries should be clearly defined
368 ## Professional Standards for Error Handling
370 ### Error Handling Standards
371 - **Comprehensive Checking**: All potential errors should be checked
372 - **Clear Reporting**: Error reporting should be clear and consistent
373 - **Robust Recovery**: Error recovery mechanisms should be in place
374 - **Defensive Programming**: Defensive coding techniques should be used effectively
376 ### Error Communication Standards
377 - **Clear Messages**: Error messages should be clear and actionable
378 - **Consistent Patterns**: Error reporting patterns should be consistent
379 - **Appropriate Details**: Error details should be appropriate for the context
380 - **User-Friendly**: Error communication should be user-friendly
382 ### Quality Assurance Standards
383 - **Error Handling**: Comprehensive error checking and handling
384 - **Input Validation**: Validate all inputs at system boundaries
385 - **Resource Management**: Proper acquisition and release of error resources
386 - **Security Considerations**: Consider security implications of error handling