Error Handling Design C#
Contents |
resources Windows Server 2012 resources Programs MSDN subscriptions Overview Benefits Administrators Students Microsoft Imagine Microsoft Student Partners ISV Startups TechRewards Events Community Magazine Forums Blogs Channel 9 Documentation APIs and reference c# error handling in constructor Dev centers Retired content Samples We’re sorry. The content you requested has
C# Error Handling Get Line Number
been removed. You’ll be auto redirected in 1 second. Enterprise Library Enterprise Library 5.0 – May 2011 Developer's Guide c# error handling framework Developer's Guide Chapter 3 - Error Management Made Exceptionally Easy Chapter 3 - Error Management Made Exceptionally Easy Chapter 3 - Error Management Made Exceptionally Easy Foreword Preface The Team Who c# error handling techniques Brought You This Guide Copyright and Terms of Use Chapter 1 - Welcome to the Library Chapter 2 - Much ADO about Data Access Chapter 3 - Error Management Made Exceptionally Easy Chapter 4 - As Easy As Falling Off a Log Chapter 5 - A Cache Advance for your Applications Chapter 6 - Banishing Validation Complication Chapter 7 - Relieving Cryptography
C# Error Handling Class
Complexity Chapter 8 - An Authentic Approach to Token Identity Appendix A - Dependency Injection with Unity Appendix B - Dependency Injection in Enterprise Library Appendix C - Policy Injection in Enterprise Library Appendix D - Enterprise Library Configuration Scenarios Appendix E - Encrypting Configuration Files 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. Chapter 3 - Error Management Made Exceptionally Easy Introduction Let's face it, exception handling isn't the most exciting part of writing application code. In fact, you could probably say that managing exceptions is one of those necessary tasks that absorb effort without seeming to add anything useful to your exciting new application. So why would you worry about spending time and effort actually designing a strategy for managing exceptions? Surely there are much more important things you could be doing. In fact, a robust and well-planned exception handling plan is a vital feature of your application design and implementation. It should not be an afterthought. If you don't have
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies error handling in c# best practices of this site About Us Learn more about Stack Overflow the company Business error handling c# mvc Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask
Error Handling In Asp.net C#
Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign https://msdn.microsoft.com/en-us/library/ff953192(v=pandp.50).aspx up Design Pattern for Error Handling up vote 1 down vote favorite I've ran into this problem a few times on various projects, and I've wondered if there's a better solution than the one I normally end up using. Say we have a series of methods that need to execute, and we want to know if something goes wrong within one of http://stackoverflow.com/questions/21476716/design-pattern-for-error-handling the methods and break out gracefully (potentially undo-ing any previous changes...), I typically do the following (pseudo C# because it's what I'm most familiar with): private bool SomeMethod() { bool success = true; string errorMessage = null; success = TestPartA(ref errorMessage); if (success) { success = TestPartB(ref errorMessage); } if (success) { success = TestPartC(ref errorMessage); } if (success) { success = TestPartD(ref errorMessage); } //... some further tests: display the error message somehow, then: return success; } private bool TestPartA(ref string errorMessage) { // Do some testing... if (somethingBadHappens) { errorMessage = "The error that happens"; return false; } return true; } I just wondered (and this is my question) if there's a better methodology for coping with this kind of thing. I seem to end up writing a lot of if statements for something that seems like it should be slicker. I've been suggested having a loop over a set of delegate functions, but I'd be worried that would be over-engineering the solution, unless there's a clean way to do it. c# asp.net design-patterns error-handling custom-error-handling share|improve this question edited Jan 31 '14 at
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 About Us Learn more about Stack Overflow the company Business Learn more about http://programmers.stackexchange.com/questions/147059/the-modern-way-to-perform-error-handling hiring developers or posting ads with us Programmers Questions Tags Users Badges Unanswered Ask Question _ Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. Join them; it only takes a minute: Sign up Here's how it works: Anybody can ask a question Anybody can answer The best answers are voted up and rise to the top The modern way to perform error handling… up vote 104 down error handling vote favorite 30 I've been pondering this problem for a while now and find myself continually finding caveats and contradictions, so I'm hoping someone can produce a conclusion to the following: Favour exceptions over error codes As far as I'm aware, from working in the industry for four years, reading books and blogs, etc. the current best practice for handling errors is to throw exceptions, rather than returning error codes (not necessarily an error code, but a c# error handling type representing an error). But - to me this seems to contradict... Coding to interfaces, not implementations We code to interfaces or abstractions to reduce coupling. We don't know, or want to know, the specific type and implementation of an interface. So how can we possibly know what exceptions we should be looking to catch? The implementation could throw 10 different exceptions, or it could throw none. When we catch an exception surely we're making assumptions about the implementation? Unless - the interface has... Exception specifications Some languages allow developers to state that certain methods throw certain exceptions (Java for example, uses the throws keyword.) From the calling code's point of view this seems fine - we know explicitly which exceptions we might need to catch. But - this seems to suggest a... Leaky abstraction Why should an interface specify which exceptions can be thrown? What if the implementation doesn't need to throw an exception, or needs to throw other exceptions? There's no way, at an interface level, to know which exceptions an implementation may want to throw. So... To conclude Why are exceptions preferred when they seem (in my eyes) to contradict software best practices? And, if error codes are so bad (and I don't need to be sold on the vices of error codes), is there another alternative? What is the current (or soon to be) state of th