19. Recursion

 
[Page 575]
The Goddess Chalchihuitlicue, found in the Valley of Mexico, 1300-1500 AD (stone), Aztec / Muse de l'Homme, Paris, France / Bridgeman Art Library

This part introduces the use of exception handling and assertions to make your programs robust and correct, the use of input and output to manage and process a large quantity of binary data, and the use of recursion to write methods for solving inherently recursive problems.


[Page 576]

Prerequisites for Part 4

All the chapters after Chapter 17 are designed to minimize dependencies so that they can be reordered flexibly.

Chapter 17, "Exceptions and Assertions," can be covered after Chapter 9, "Inheritance and Polymorphism." Chapter 18, "Binary I/O," is usually covered after Chapter 17.

The concept of recursion and how to write simple recursive programs in 19.119.3 can be covered after Chapter 6, "Arrays."


 

Chapter 17 Exceptions and Assertions

 

Chapter 18 Binary I/O

 

Chapter 19 Recursion

[Page 577]

Chapter 17. Exceptions and Assertions

Mayan God Shel, Mexico. Photographer: Philip Coblentz. Courtesy Brand X Pictures

Objectives

  • To understand exceptions and exception handling (17.217.3).

  • To distinguish exception types: Error (fatal) vs. Exception (non-fatal), and checked vs. unchecked (17.3).

  • To declare exceptions in a method header (17.4.1).

  • To throw exceptions in a method (17.4.2).

  • To write a try-catch block to handle exceptions (17.4.3).

  • To explain how an exception is propagated (17.4.3).

  • To use the finally clause in a try-catch block (17.5).

  • To know when to use exceptions (17.6).

  • To rethrow exceptions in a try-catch block (17.7).

  • To create chained exceptions (17.8).

  • (Optional) To declare custom exception classes (17.9).

  • (Optional) To apply assertions to help ensure program correctness (17.10).


[Page 578]

17.1. Introduction

Three categories of errors (syntax errors, runtime errors, and logic errors) were introduced in 2.15, "Programming Errors." Syntax errors arise because the rules of the language have not been followed. They are detected by the compiler. Runtime errors occur while the program is running if the environment detects an operation that is impossible to carry out. Logic errors occur when a program doesn't perform the way it was intended to. In general, syntax errors are easy to find and easy to correct because the compiler indicates where they came from and why they occurred. You can use the debugging techniques introduced in 2.16, "Debugging," to find logic errors. This chapter introduces using exception handling to deal with runtime errors and using assertions to help ensure program correctness.

 


Introduction to Java Programming-Comprehensive Version
Introduction to Java Programming-Comprehensive Version (6th Edition)
ISBN: B000ONFLUM
EAN: N/A
Year: 2004
Pages: 503

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net