ch15 - Java Programming Fourth Edition Chapter 15 Exception...

Info iconThis preview shows pages 1–14. Sign up to view the full content.

View Full Document Right Arrow Icon
Java Programming Fourth Edition Chapter 15 Exception Handling
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Java Programming, Fourth Edition 2 Objectives • Learn about exceptions • Understand the limitations of traditional error handling • Try code and catch Exceptions • Throw and catch multiple Exceptions • Use the finally block
Background image of page 2
Java Programming, Fourth Edition 3 Objectives (continued) • Understand the advantages of exception handling • Specify the Exceptions a method can throw • Trace Exceptions through the call stack • Create your own Exceptions • Use an assertion
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Java Programming, Fourth Edition 4 Learning About Exceptions • Exceptions – Unexpected or error condition – Not usual occurrences – Causes • Call to file that does not exist • Try to write to full disk • User enters invalid data • Program attempts to divide value by 0
Background image of page 4
Java Programming, Fourth Edition 5 Learning About Exceptions (continued) • Exception handling – Object-oriented techniques used to manage Exception errors • Exceptions – Objects – Descend from Throwable class
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Java Programming, Fourth Edition 6 Learning About Exceptions (continued) • Error class – Represents serious errors from which program usually cannot recover – Error condition • Program runs out of memory • Program cannot locate required class
Background image of page 6
Java Programming, Fourth Edition 7 Learning About Exceptions (continued) • Exception class – Less serious errors – Unusual conditions – Program can recover • Exception class errors – Invalid array subscript – Performing illegal arithmetic operations
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Java Programming, Fourth Edition 8 Learning About Exceptions (continued) • Throwable object Error or Exception – Examine message after error occurs – Exception message • Error preventable by using specific code within program – Error message • Program terminates • No program code can prevent
Background image of page 8
Java Programming, Fourth Edition 9 The MathMistake class
Background image of page 9

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Java Programming, Fourth Edition 10 Output of the Attempted Execution of the MathMistake Application
Background image of page 10
Java Programming, Fourth Edition 11 Understanding the Limitations of Traditional Error Handling • System.exit() method – Return 1 if error is causing program termination – Or 0 if program ending normally – Circumvents displaying error message • Fault-tolerant – Designed to continue to operate when some part of system fails • Robustness – Represents degree to which system is resilient to stress
Background image of page 11

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Java Programming, Fourth Edition 12 Trying Code and Catching Exceptions • try block – Segment of code in which something might go wrong – Attempts to execute • Acknowledging exception might occur • try block includes: – Keyword try – Opening and closing curly brace – Executable statements • Which might cause exception
Background image of page 12
Java Programming, Fourth Edition 13 Trying Code and Catching Exceptions (continued)
Background image of page 13

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 14
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 46

ch15 - Java Programming Fourth Edition Chapter 15 Exception...

This preview shows document pages 1 - 14. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online