Exceptions
Although you are just learning about them now, you have probably become well-acquainted with exceptions during the last 17 previous hours. These errors turn up when you write a Java program that compiles successfully but encounters a problem as it runs.
For example, a common programming mistake is to refer to an element of an array that doesn’t exist, as in the following statements:
String[] greek = { "Alpha", "Beta", "Gamma" };System.out.println(greek[3]);
The String array greek has three elements. Because the first element of an array is numbered 0 rather than 1, the first element is greek[0], the second greek[1], and the third greek[2]. So the statement attempting to display greek[3] is erroneous. The preceding statements compile ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access