exceptions and advanced file i/o chapter 12. 12-2 handling exceptions an exception is an object that...

80
Exceptions and Advanced File I/O Chapter 12

Upload: reynold-bruce

Post on 11-Jan-2016

217 views

Category:

Documents


1 download

TRANSCRIPT

Exceptions and Advanced File I/O

Exceptions and Advanced File I/OChapter 1212-2Handling ExceptionsAn exception is an object that is generated as the result of an error or an unexpected event.Exceptions are said to have been thrown. It is the programmers responsibility to write code that detects and handles exceptions. Unhandled exceptions will crash a program.Java allows you to create exception handlers. 2

public class BadArray{ public static void main(String[] args) { // Create an array with 3 elements. int[] numbers = { 1, 2, 3 };

// Attempt to read beyond the bounds // of the array. for (int i = 0; i