Best Practices for Exception Handling
http://onjava.com/pub/a/onjava/2003/11/19/exceptions.html
The Nature of Exceptions
1. Exceptions due to programming errors
2. Exceptions due to client code errors
3. Exceptions due to resource failures
Types of Exceptions in Java
1. Checked exceptions
2. Unchecked exceptions (RuntimeException)
Best Practices for Designing the API
1. When deciding on checked exceptions vs. unchecked exceptions
2. Preserve encapsulation
3. Try not to create new custom exceptions if they do not have useful information for client code
4. Document exceptions
Best Practices for Using Exceptions
1. Always clean up after yourself
2. Never use exceptions for flow control
3. Do not suppress or ignore exceptions
4. Do not catch top-level exceptions
5. Log exceptions just once
Three Rules for Effective Exception Handling
http://today.java.net/pub/a/today/2003/12/04/exceptions.html
1. Be Specific
2. Throw Early
3. Catch Late
The Java Tutorial(Lesson: Exceptions)
http://download.oracle.com/javase/tutorial/essential/exceptions/index.html
Antipattern
http://en.wikipedia.org/wiki/Antipattern
http://www.c2.com/cgi/fullSearch
Exception handling in an n-Tier application-best practices?
3 layers: a DAL layer, a BLL layer, and a UI layer.
Propagate exceptions from the DAL up through the other two so can do cleanup in the UI and BLL if a database call fails.
Able to Trap exceptions originating locally in the BLL and UI layers.
Private Class CallOneException Inherits Exception
End Class
Private Class CallTwoException Inherits Exception
End Class
Private Sub BaseCall()
Try
CallOne
Catch CallOneEx As CallOneException
Catch CallTwoEx As CallTwoException
Catch Ex As Exception
Finally
End Try
End Sub
Private Sub CallOne()
Try
CallTwo
Catch CallTwoEx As CallTwoException
Throw
Catch Ex As Exception
Throw New CallOneException
Finally
End Try
End Sub
Private Sub CallTwo()
Try
Catch ex As Exception
Throw New CallTwo Exception
Finally
End Try
End Sub
Exception handling in 3-Tier Architecture
http://www.codeproject.com/KB/exception/expceptionhandling-3-tier.aspx
Logging Exceptions: Where to Log Exceptions?
http://tutorials.jenkov.com/java-exception-handling/logging-where-to-log-exceptions.html
Exception Handling Best Practices in .NET
http://www.codeproject.com/KB/architecture/exceptionbestpractices.aspx
Creating and Throwing Exceptions (C# Programming Guide)
http://msdn.microsoft.com/en-us/library/ms173163.aspx
Things to Avoid When Throwing Exceptions
1. Exceptions should not be used to change the flow of a program as part of ordinary execution. Exceptions should only be used to report and handle error conditions.
2. Exceptions should not be returned as a return value or parameter instead of being thrown.
3. Do not throw System.Exception, System.SystemException, System.NullReferenceException, or System.IndexOutOfRangeException intentionally from your own source code.
4. Do not create exceptions that can be thrown in debug mode but not release mode. To identify run-time errors during the development phase, use Debug Assert instead.
Wednesday, October 27, 2010
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment