Net Error Handling Strategies
Contents |
We would catch it and write it to a log. More sophisticated versions even featured a stack trace. Yes, really, we were that advanced :) The reason we did that was simple, VB didn't have
Owasp Information Leakage And Improper Error Handling
structured exception handling and if your application threw an unhandled error it simply crashed. There was owasp improper error handling no default way of knowing where the exception had taken place. .NET has structured exception handling, but the VB mindset of wrapping every piece application error message security vulnerability of code in a try-catch block, where the catch catches System.Exception, is still common, I see it again and again in enterprise development teams. Usually it includes some logging framework and looks something like this: try { // do something
Owasp Error Handling Cheat Sheet
} catch (Exception exception) { Logger.LogException("Something bad just happened", exception); } Catching System.Exception is the worst possible exception handling strategy. What happens when the application continues executing? It's probably now in an inconsistent state that will cause extremely hard to debug problems in some unrelated place, or even worse, inconsistent corrupt data that will live on in the database for years to come. If you re-throw from the catch block the exception will get caught again in the calling method
Poor Error Handling Server Error Message ( 10932 )
and you get a ton of log messages that don't really help you at all. It is much better to simply allow any exceptions to bubble up to the top of the stack and leave a clear message and stack trace in a log and, if possible, some indication that there's been a problem on a UI. In fact there are only three places where you should handle exceptions; at the process boundary, when you are sure you can improve the experience of the person debugging your application, and when your software can recover gracefully from an expected exception. You should always catch exceptions at the process boundary and log them. If the process has a UI, you should also inform the user that there has been an unexpected problem and end the current business process. If you allow the customer to struggle on you will most likely end up with either corrupt data, or a further, much harder to debug, problem further down the line. Improving the debugging experience is another good reason for exception handling. If you know something is likely to go wrong; a configuration error for example, it's worth catching a typed error (never System.Exception) and adding some context. You could explain clearly that a configuration section is missing or incorrect and give explicit instructions on how to fix it. Be very careful though, it is very easy to end up sending someone on
Portability Issues C++ & MFC » General Array Handling Binary Trees Bits and Bytes Buffer & Memory Manipulation Callbacks Classes and Class Use Collections Compression Drag and Drop error message on page Events Exceptions External Links File I/O Function Calling Linked Lists Memory Tracking
Error Handling Best Practices
Object Oriented Programming (OOP) Open FAQ Parsing Patterns Pointers Portability RTTI Serialization Singletons Standard Template Library (STL) Templates poor error handling: unhandled exception Tutorials Date & Time » General Date Controls Time Routines C++/CLI » .NET Framework Classes General ASP/ASP.NET Boxing and UnBoxing Components Garbage Collection and Finalizers Interop Moving from Unmanaged http://mikehadlow.blogspot.com/2009/08/first-rule-of-exception-handling-do-not.html Processes & Threads Templates Visual Studio .NET 2003 String Programming » General CString Alternatives CString Extensions CString Manipulation Open FAQ Regular Expressions String Arrays String Conversions .NET COM-based Technologies » ATL & WTL Programming » General ATL Active Scripting ActiveX Controls Database Debugging External links Graphics Support Misc. Performance Printing Tutorials Utilities Windows Template Library (WTL) ActiveX Programming » General http://www.codeguru.com/cpp/misc/misc/system/article.php/c3859/Error-Handling-Strategies.htm Active Scripting ActiveX Controls ActiveX Documents Apartments & Threading Error Handling External links General COM/DCOM Misc. Registry Security Structured Storage Tutorials Wrappers COM+ » General COM Interop Managed Code / .NET SOAP and Web Services Shell Programming » General Open FAQ Shortcuts Tray Icons Previous Section Manager Controls » Property Sheet » Open FAQ Property Sheet Buttons Sizing Wizards Button Control » Advanced Buttons Bitmap Buttons Flat Buttons Menus Non-Rectangular buttons Windows XP ComboBox » Colour Pickers DropDown Font selection combos Multicolumn combos Special Effects Tooltips Edit Control » Background & Color Editors Keyboard Masked Edit Controls Passwords and Security Spin Controls Transparent ImageList Control » Open FAQ ListBox Control » Checkboxes Color Listboxes Drag & Drop LEDs ListView Control » Advanced Background color and image Checkboxes Columns Custom Drawing Data Deleting Drag & Drop Editing items and subitem FilterBar Grid lines Header Control Introduction Miscellaneous Navigation New ListView control (IE 4.0) Printing Property Lists Reports Scrollbars Selection Sorting Tooltip & Titletip Using images Views Menu » Alternative menu Bitmapped menus Dockable menus Message and C
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site http://stackoverflow.com/questions/566358/error-handling-logging-strategy About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join https://msdn.microsoft.com/en-us/library/windows/desktop/ms688560(v=vs.85).aspx the Stack Overflow Community Stack Overflow is a community of 6.2 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up Error handling/Logging strategy up vote error handling 7 down vote favorite 5 Could you guys share your knowledge about Error handling/Logging strategy for asp.net 3.5 web based application? c# asp.net design share|improve this question edited Feb 19 '09 at 17:40 GEOCHET 16.4k156085 asked Feb 19 '09 at 17:36 Jeremy Thomson 40931117 add a comment| 4 Answers 4 active oldest votes up vote 15 down vote Log4net logging: What have you found to improper error handling be useful? What are the best practices to log an error? Logging Best Practices What To Write Into Log File? What should be included in the state of the art error and exception handling strategies? What information should I be logging in my web app? Logging is a very critical part of every application, so it is important that you do it well. share|improve this answer answered Jul 3 '09 at 17:09 DevinB 6,43753348 add a comment| up vote 2 down vote You should consider log4net. See this question for more information. It is very robust, fast, and easy to use. share|improve this answer answered Feb 19 '09 at 17:39 Geoff 8,01652746 add a comment| up vote 2 down vote When an error occurs you should not attempt to catch it or log it directly in your application's code unless it is an error you can hope to recover from. For example, if you have a data-driven web application and the database is offline, that is not something you can recover from. But if you are sending an email and have two email servers and the first one is down, you might be able t
Studio 2015 products Visual Studio Team Services Visual Studio Code Visual Studio Dev Essentials Office Office Word/Excel/PowerPoint Microsoft Graph Outlook OneDrive/Sharepoint Skype Services Store Cortana Bing Application Insights Languages & platforms Xamarin ASP.NET C++ TypeScript .NET - VB, C#, F# Server Windows Server SQL Server BizTalk Server SharePoint Dynamics Programs & communities Students Startups Forums MSDN Subscriber downloads Sign in Search Microsoft Search Windows Dev Center Windows Dev Center Explore Why Windows What’s new for Windows 10 Intro to Universal Windows Platform Dev Center Benefits Develop for accessibility Build for enterprise Docs Windows apps Get started Design and UI Develop API reference Publish Monetize Promote Games Get started UI design Develop Publish Desktop Get started Design Develop API reference Test and deploy Compatibility Windows IoT Microsoft Edge Windows Holographic Downloads Samples Support Dashboard Explore Why Windows What’s new for Windows 10 Intro to Universal Windows Platform Dev Center Benefits Develop for accessibility Build for enterprise Docs Windows apps Get started Design and UI Develop API reference Publish Monetize Promote Games Get started UI design Develop Publish Desktop Get started Design Develop API reference Test and deploy Compatibility Windows IoT Microsoft Edge Windows Holographic Downloads Samples Support Dashboard COM Fundamentals Guide Error Handling in COM Error Handling in COM Error Handling Strategies Error Handling Strategies Error Handling Strategies Structure of COM Error Codes Codes in FACILITY_ITF Using Macros for Error Handling COM Error Handling in Java and Visual Basic Error Handling Strategies Handling Unknown Errors 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. Error Handling Strategies Because interface methods are virtual, it is not possible for a caller to know the full set of values that may be returned from any one call. One implementation of a method may return five values; another may return eight. The documentation lists common values that may be returned for each method; these are the values that you must check for and handle in your code because they have special meanings. Other values may be returned, but because they are not meaningful, you do not need to write special code to handle them. A simple check for zero or nonzero is adequate. HRESULT Values The return value of COM functions and methods is an HRESULT. The values of some HRESULTs have been changed in COM to eliminate