Code Complete Error Handling
Contents |
by Steve McConnell Published by Microsoft Press Code Complete, Second Edition Preface Who Should Read This Book? Where Else Can You Find This Information? Key Benefits of what is error handling This Handbook Why This Handbook Was Written Author Note Acknowledgments About the
Error Handling Java
Author Steve McConnell I. Laying the Foundation 1. Welcome to Software Construction 2. Metaphors for a Richer Understanding of error handling testing in software testing Software Development 3. Measure Twice, Cut Once: Upstream Prerequisites 4. Key Construction Decisions II. Creating High-Quality Code 5. Design in Construction 6. Working Classes 7. High-Quality Routines 8. Defensive Programming error handling php 9. The Pseudocode Programming Process III. Variables 10. General Issues in Using Variables 11. The Power of Variable Names 12. Fundamental Data Types 13. Unusual Data Types IV. Statements 14. Organizing Straight-Line Code 15. Using Conditionals 16. Controlling Loops 17. Unusual Control Structures 18. Table-Driven Methods 19. General Control Issues V. Code Improvements 20. The Software-Quality Landscape 21. Collaborative Construction 22. Developer
Error Handling In Vb
Testing 23. Debugging 24. Refactoring 25. Code-Tuning Strategies 26. Code-Tuning Techniques VI. System Considerations 27. How Program Size Affects Construction 28. Managing Construction 29. Integration 30. Programming Tools VII. Software Craftsmanship 31. Layout and Style 32. Self-Documenting Code 33. Personal Character 34. Themes in Software Craftsmanship 35. Where to Find More Information Bibliography Index About the Author Error-Handling TechniquesAssertions are used to handle errors that should never occur in the code. How do you handle errors that you do expect to occur? Depending on the specific circumstances, you might want to return a neutral value, substitute the next piece of valid data, return the same answer as the previous time, substitute the closest legal value, log a warning message to a file, return an error code, call an error-processing routine or object, display an error message, or shut down—or you might want to use a combination of these responses.Here are some more details on these options:Return a neutral value. Sometimes the best response to bad data is to continue operating and simply return a value that's known to be harmless. A numeric
in, Garbage out" not allowed in modern programming. Check the values of all data from external sources. Check the values of all routine input parameters Decide error handling best practices how to handle bad inputs 8.2 Assertions Use assertions to check : error handling techniques that an input parameter's value falls into expected range. that a file or stream is open(or closed)
Types Of Error Handling
that a file or stream is open for read-only, write-only or both read and write. that the value of an input-only variable is not changed by a routine. that https://www.safaribooksonline.com/library/view/code-complete-second/0735619670/ch08s03.html a point is non-null. that an array or other containers passed in has at least X number of elements. that a table has been initialized to contain real values. that a container is empty or (full) that the results from a highly optimized, complicated routine match the results from a slower but clearly written routine. Guidelines for Using https://yikliu.wordpress.com/2011/01/21/code-complete-ch-8-defensive-programming/ Assertions Use error- handling code for conditions you expect to occur; use assertions for conditions that should never occur. Avoid putting executable code into assertion. Use assertions to document and verify preconditions and postconditions. preconditions: client codes' obligation to the code it calls. postcondition: routines or classes' obligations to the code that uses it. For highly robust code, assert and then handle the error anyway. 8.3 Error-handling Techniques Return a neutral value Substitute the next piece of valid data. Return the same answer as the previous time. Substitute the closest legal value Log a warning message to file. Return an error code. Set the value to a status variable. Return status as the function's return value Throw an exception by using language's built-in exception mechanism. Call an error-handling routine/object. Adv. error-handling is centrilized, Disadv: this object is too tightly coupled with rest of the application and needs to be dragged if code ports to another place. Display an error message wherever the error is encountered. Adv. minimize error-handling overhead; Disadv, spread user in
resources Windows Server 2012 resources Programs MSDN subscriptions Overview Benefits Administrators Students Microsoft Imagine Microsoft Student Partners ISV Startups TechRewards Events https://msdn.microsoft.com/en-us/library/bb397417.aspx Community Magazine Forums Blogs Channel 9 Documentation APIs and reference https://staticapps.org/articles/front-end-error-handling/ Dev centers Retired content Samples We’re sorry. The content you requested has been removed. You’ll be auto redirected in 1 second. MSDN Library MSDN Library MSDN Library MSDN Library Design Tools Development Tools and Languages Mobile and Embedded Development .NET Development error handling Office development Online Services Open Specifications patterns & practices Servers and Enterprise Development Speech Technologies Web Development Windows Desktop App Development TOC Collapse the table of content Expand the table of content This documentation is archived and is not being maintained. This documentation is archived and is not being maintained. Complete Example code complete error for Error Handlers Other Versions Visual Studio 2010 .NET Framework 4 Visual Studio 2008 This code example includes elements for both page-level and application-level exception handling. Code Example Files The example consists of the following files: Web.config Global.asax Default.aspx ExceptionUtility (to be put in the App_Code folder) GenericErrorPage.aspx HttpErrorPage.aspx Http404ErrorPage.aspx DefaultRedirectErrorPage.aspx Web.config The following example shows the Web.config file. The customErrors section specifies how to handle errors that occur with file types that are mapped to ASP.NET, such as .aspx, .asmx, and .ashx files. (In IIS 6.0 and in IIS 7.0 in classic mode, static content files such as .html and .jpg files are not mapped to ASP.NET.) The settings in the example customErrors section cause any unhandled HTTP 404 (file not found) errors to be directed to the Http404ErrorPage.aspx file. These HTTP 404 errors would occur if a request were made for an .aspx file, .asmx file, and so on and i
rarely go right all the time in the real world. Error handling is a vital part of any application's user experience, and if done well, can leave your users feeling informed and properly considered. Most errors that an application encounters can be grouped into a few categories: Input Errors: Information provided by the user is unacceptable for some reason. This includes errors from form validation, duplicate actions, uniqueness issues, resources not found, etc. Authorization Errors: A user is attempting to perform an action to which he/she does not have permission. Availability Errors: A resource that is needed to complete the user's action is unavailable for some reason. This may be expected (scheduled maintenance) or unexpected (server crash!). Unexpected Errors: These are errors that likely indicate a bug in the application, such as unhandled exceptions. Almost every application will have instances of each of these error categories at some point. Handling each appropriately is key to keeping users who encounter errors from becoming angry users. Front-End vs. Back-End Error Handling In web application back-ends, expected errors are usually handled by displaying or responding with some kind of error message, while unexpected errors will short circuit the normal response process and display a generic error page. Applications that are very poorly configured might even spit out internal error details to the end user. For the most part, back-end applications are not always good at helping a user recover from an error, but they are pretty good at letting the user know something is wrong. Front-end applications, for better or worse, have no built-in mechanism for halting everything and displaying an error message. When a JavaScript error occurs, usually one of three things happens: The application keeps running, but something the user expected to happen doesn't happen. The most common user response to this type of error is simply to try the action again (and again) hoping it will "work this time." The application stops running but displays no sign that it has stopped. The user will retry the action (or try to perform a different one) to no avail. If the error happened early enough, the entire page may be prevented from being properly set up and the user will just see a white screen. These scenarios, from a user experience perspective, are terrible. They are likely to lead to user frustration, a feeling of helplessness, and eventual anger. Front-end applications are in many ways more flexible than back-end ap