1. Learn
  2. /
  3. Courses
  4. /
  5. Data Types and Exceptions in Java

Connected

Exercise

Throws

As an exception is thrown, a method can elect to handle the exception with a try-catch or throw the exception to its caller (passing the buck). In this exercise, you will see how to throw an exception rather than handle it with try/catch.

Instructions

100 XP
  • Add a try block around the code to getScore(3) and print it.
  • Add a catch block to handle the ArrayIndexOutOfBoundsException caused in the getScore() method.
  • Have getScore(int) throw ArrayIndexOutOfBoundsException instead of try/catching the exception.