Tino APCS

Exceptions and File I/O

Lesson Overview: Java provides a structured approach for dealing with errors that can occur while a program is running. This approach is referred to as “exception-handling.” The word “exception” is meant to be more general than “error.” Exception-handling is used to keep a program running even though an error is encountered that would normally stop the program. This lesson will explore file input and output (I/O) as an example of how exceptions are used.

Lesson Vocab
catch

A keyword defining a catch block, which "catches" an exception as its parameter. Must be paired with a try block.

ERROR

Describes when a program does not do what it is intended to. Does not necessarily mean the program failed syntax-wise.

EXCEPTION

Represents a problem that the compiler was unable to detect before the execution of the program (runtime error). Exceptions are stored as Exception Objects in Java, which contain information about the error.

PRECONDITION

A statement of everything that must be true when a method is called in order for the method to work properly.

POSTCONDITION

A statement of everything that is true when a method completes its job.

try

A keyword defining a try block, which attempts to execute a piece of code that may throw an Exception. Must be paired with a catch block.