Help: Catching Exceptions


Help is available for each task, or you can go straight to the solution source code.

Task 1

Add a try and catch block to the main you have been provided. Check for NullPointerException and ArrayIndexOutOfBoundsException exceptions coming from the calls to search. The two last search calls generate the exceptions--you will have to comment out the second search to get the third to be executed. Generate "array was null" upon NullPointerException and "n>array.length" upon ArrayIndexOutOfBoundsException.
You can use a single try block around all the search calls with two catch blocks.

Copyright © 1996-1997 MageLang Institute. All Rights Reserved.