i. Uningenious
ii. Partners – May 4
i. Unchecked, checked, error
ii. Error.java
i. Catching locally vs on call stack
1. Rule of thumb – checked exceptions must be
caught somewhere in a program. So, a
method that invokes it must either catch it or throw it, etc. If it throws it, any method that calls it
must either catch it or throw it. Etc…
a. Recursive definition
ii. Catch specific Exceptions
iii. Can have multiple
iv. Exception Hierarchy
1. http://www.programcreek.com/wp-content/uploads/2009/02/hierarchy.png
2. In general – runtime exceptions are
unchecked, ioexceptions are checked
v. Should order from most specific to least
specific
1. Why?
2. Generic Exceptions
a. catch(Exception e)
b. but, be careful – you shouldn’t just sweep
exceptions under the rug…
i. But, we throw them instead of passing them
ii. Exception Constructors
1. ()
2. (String message)
iii. Exception methods
1. getMessage()
2. PrintStackTrace()
i. Avoid try/catch/finally
ii. Nested try/finally and try/catch
i. Try/catch/finally
ii. Be careful to make sure you don’t get ‘might
not be initialized’ compile-time errors
i. It depends
ii. Unchecked might be ‘easier’
iii. But, checked is often correct