effective exceptions

Download Effective exceptions

If you can't read please download the document

Upload: parag

Post on 20-May-2015

430 views

Category:

Technology


4 download

TRANSCRIPT

  • 1. Writing Effective Exceptions In Java Parag Shah http://www.diycomputerscience.com

2. Exceptions In JavaWhat were the old ways of error handling ?http://rlc.vlinder.ca/blog/2010/01/error-handling-in-c/What are Exceptions ?Why should we use them ? 3. Exceptions In Java 4. Creating Custom ExceptionsExtend the Exception class for normal exceptionsExtend the RuntimeException class for runtimeexceptionsExtend Error for errorsNever extend ThrowableRedefine all constructors 5. Best Practices - Throwing Using checked vs. unchecked Exception 6. Best Practices - Throwing Throw early catch late 7. GUIApplication Data Encountered problem... throw anGUIDataClass ExceptionClassimediately ! Application ClassHandle theExceptionas late as possible 8. Best Practices - ThrowingThrow an appropriate Exception 9. GUI Application DataEncounteredproblem...throw anGUI DataClassExceptionClass imediately !ApplicationClass Log theexception here 10. Best Practices - Catching Do not suppress Exceptions 11. Best Practices - Catching Do not catch high level Exceptions 12. Best Practices - Catching Cleaning up with finally 13. Best Practices - CatchingLog Exceptions only once 14. Best Practices - CatchingCatching vs. Propagating 15. Exceptions ResourcesBest practices with Exceptions - http://www.wikijava.org/wiki/10_best_practices_with_Exceptions