

























Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!


























(^) An exception is an event, which occurs during the execution of a program, that disrupts the normal flow of the program's instructions.
(^) Separating Error-Handling Code from "Regular" Code (^) Propagating Errors Up the Call Stack (^) Grouping and Differentiating Error Types
(^) No need to declare the exception in method’s signature (^) No compile time checking (^) Usually indicate programming error (^) e.g. NullPointerException
(^) Indicate error in the underlying JVM (^) Error are external to the application (^) Application does not usually have to deal with these class of Exceptions (^) e.g. OutOfMemoryError
(^) Exceptions v/s Errors (^) Errors are for JVM (^) Exceptions for rest of us (^) Checked v/s Unchecked exceptions (^) Can caller recover from this error? (^) Yes: checked (^) No: unchecked
(^) What went wrong? (^) Where did it go wrong? (^) Why did it go wrong? (^) If your exception does not provide answers to all these questions, you are doing something wrong!
(^) Exceptions are expensive for the JVM (^) Creating stack traces requires resources and CPU (^) the Java VM requires more efforts to handle a thrown exception than a normal method
(^) Log the error and throw the same exception again (^) Messy log file (^) Achieves nothing
(^) The caller does not know the nature of error – hinders error handling
public SomeInterface buildInstance(String className) { SomeInterface impl = null; try { Class clazz = Class.forName(className); impl = (SomeInterface)clazz.newInstance(); } catch (Exception e) { log.error("Error creating class: " + className); } return impl; }
catch (NoSuchMethodException e) { throw new MyServiceException("Blah: " + e.getMessage()); }