2014-03-21

posted Mar 21, 2014, 5:36 AM by Samuel Konstantinovich   [ updated Mar 22, 2014, 10:07 AM ]
Goal: Exceptions and Generics.
Summary:
Checked vs. Unchecked exceptions.

Unchecked exceptions (runtime exceptions like indexOutOfBounds, DivideByZero, and NullPointerExceptions)
are allowed to be passed out of your code all the way to the JVM. These are serious problems that are agreed upon to be things that should really stop the program. You can still catch them, but it isn't required.

Checked Exceptions (the regular Excepiton and many others) must be caught in your method, OR the method must be declared to throw it. 

You should throw IndexOutOfBoundsException() in your linked list code. This is an UNCHECKED exception that
a) accurately describes the problem you encountered
b) does not require you to declare that your methods throw it, nor require you to catch it. 

Here is reference on exceptions.
http://docs.oracle.com/javase/tutorial/essential/exceptions/throwing.html

LAB+HOMEWORK this weekend:
Make your MyLinkedList class accept generic types:  MyLinkedList<T>

You are submitting a zip with two files:
MyLinkedList.java
Node.java

I will test it on Integer() after you submit it. 
SUBMIT IT BY 1159PM SUNDAY. TEST IT FIRST! Post how you tested it on the mailing list if you aren't sure if it is sufficient.


Comments