Java Programming Fifth Edition

Slides:



Advertisements
Similar presentations
Pearson Education, Inc. All rights reserved. 1.. Exception Handling.
Advertisements

Topics Introduction Types of Errors Exceptions Exception Handling
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide
Exception Handling Chapter 15 2 What You Will Learn Use try, throw, catch to watch for indicate exceptions handle How to process exceptions and failures.
An Introduction to Java Programming and Object- Oriented Application Development Chapter 8 Exceptions and Assertions.
C++ Programming: Program Design Including Data Structures, Fourth Edition Chapter 15: Exception Handling.
1 Handling Exceptions COSC 1567 C++ Programming Lecture 11.
JAVA: An Introduction to Problem Solving & Programming, 6 th Ed. By Walter Savitch ISBN © 2012 Pearson Education, Inc., Upper Saddle River,
Chapter 16: Exception Handling C++ Programming: From Problem Analysis to Program Design, Fifth Edition.
Objectives In this chapter you will: Learn what an exception is Learn how to handle exceptions within a program See how a try / catch block is used to.
Chapter 8Java: an Introduction to Computer Science & Programming - Walter Savitch 1 Chapter 8 l Basic Exception Handling »the mechanics of exceptions l.
© The McGraw-Hill Companies, 2006 Chapter 15. © The McGraw-Hill Companies, 2006 Exceptions an exception is an event that occurs during the life of a program.
JAVA: An Introduction to Problem Solving & Programming, 5 th Ed. By Walter Savitch and Frank Carrano. ISBN © 2008 Pearson Education, Inc., Upper.
C++ Programming: From Problem Analysis to Program Design, Third Edition Chapter 16: Exception Handling.
Lesson 16 Exceptions Lesson Exceptions1. Murphy’s Law Anything that can go wrong will go wrong Lesson Exceptions2.
Exception Handling Chapter 12.  Errors- the various bugs, blunders, typos and other problems that stop a program from running successfully  Natural.
Slides prepared by Rose Williams, Binghamton University ICS201 Exception Handling University of Hail College of Computer Science and Engineering Department.
Exception Handling. 2 Two types of bugs (errors) Logical error Syntactic error Logical error occur  due to poor understanding of the problem and solution.
EXCEPTIONS Def: An exception is a run-time error. Examples include: attempting to divide by zero, or manipulate invalid data.
1 Lecture#8: EXCEPTION HANDLING Overview l What exceptions should be handled or thrown ? l The syntax of the try statement. l The semantics of the try.
12.1 Exceptions The limitations of traditional methods of exception handling Error conditions are a certainty in programming Programmers make.
Java Software Solutions Foundations of Program Design Sixth Edition
1 Chapter Eight Exception Handling. 2 Objectives Learn about exceptions and the Exception class How to purposely generate a SystemException Learn about.
Java Programming Exceptions Handling. Topics: Learn about exceptions Try code and catch Exceptions Use the Exception getMessage() method Throw and catch.
Chapter 12: Exception Handling
UNIT 3 TEMPLATE AND EXCEPTION HANDLING. Introduction  Program errors are also referred to as program bugs.  A C program may have one or more of four.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Java Software Solutions Foundations of Program Design Sixth Edition by Lewis.
Chapter 14: Exception Handling. Objectives In this chapter, you will: – Learn what an exception is – Learn how to handle exceptions within a program –
Exception Handling Unit-6. Introduction An exception is a problem that arises during the execution of a program. An exception can occur for many different.
Exceptions in Java. Exceptions An exception is an object describing an unusual or erroneous situation Exceptions are thrown by a program, and may be caught.
JAVA: An Introduction to Problem Solving & Programming, 5 th Ed. By Walter Savitch and Frank Carrano. ISBN © 2008 Pearson Education, Inc., Upper.
HANDLING EXCEPTIONS Chapter 9. Outline  Learn about the limitations of traditional error-handling methods  Throw exceptions  Use try blocks  Catch.
Computer Programming with JAVA Chapter 8. Exception Handling Basic Exception Handling the mechanics of exceptions Defining and Using Exceptions some "simple"
Exceptions in C++. Exceptions  Exceptions provide a way to handle the errors generated by our programs by transferring control to functions called handlers.
Exceptions and Assertions Chapter 15 – CSCI 1302.
Chapter 15: Exception Handling C++ Programming: Program Design Including Data Structures, Fifth Edition.
Lecture 18B Exception Handling and Richard Gesick.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved Enhanced Car Payment Calculator Application Introducing Exception Handling.
Eighth Lecture Exception Handling in Java
16 Exception Handling.
Jim Fawcett CSE687-OnLine – Object Oriented Design Summer 2017
Exceptions Exceptions are used to signal that an unexpected event has happened in a program C++ will generate exceptions for some errors in the program.
Jim Fawcett CSE687 – Object Oriented Design Spring 2001
Jim Fawcett CSE687 – Object Oriented Design Spring 2015
Introduction Exception handling Exception Handles errors
Part IX Fundamentals of C and C++ Programming Exception Handling
Exceptions C++ Interlude 3
Chapter 14: Exception Handling
YG - CS170.
Exception Handling and
EE422C Software Implementation II
Exception Handling Chapter 9.
Chapter 11—Exceptions Handling Exceptions Throwing Exceptions.
Advanced Java Programming
Exceptions with Functions
Chapter 12 Exception Handling
Exceptions Problems in a Java program may cause exceptions or errors representing unusual or invalid processing. An exception is an object that defines.
Exception Handling and Reading / Writing Files
Exception Handling Chapter 9 Edited by JJ.
Exception Handling Oo28.
Exceptions CSCE 121 J. Michael Moore
Chapter 13 Exception Handling
Object-Oriented Programming Using C++ Second Edition
Java Exceptions Dan Fleck CS211.
Fundaments of Game Design
Tutorial Exceptions Handling.
Chapter 11: Exception Handling
CMSC 202 Exceptions 2nd Lecture.
Exception Handling.
Presentation transcript:

Java Programming Fifth Edition Chapter 11 Exception Handling

Learning About Exceptions Unexpected or error conditions 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 Invalid array subscript Performing illegal arithmetic operations Java Programming, Fifth Edition

Learning About Exceptions (continued) Do not necessarily have to deal with Exception Let the offending program terminate Abrupt and unforgiving Use a decision to avoid an error, no exception-handling techniques needed. Can be complicated (e.g. valid file name). Java Programming, Fifth Edition

Learning About Exceptions (continued) Exception handling Provides a more elegant solution for handling error conditions Fault-tolerant Designed to continue to operate when some part of system fails Robustness Represents degree to which system is resilient to stress Java Programming, Fifth Edition

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 Java Programming, Fifth Edition

Trying Code and Catching Exceptions (continued) catch block Segment of code Immediately follows try block Handles exception thrown by try block preceding it Can “catch” Object of type Exception Or Exception child class throw statement Sends Exception out of method Can be handled elsewhere Java Programming, Fifth Edition

Trying Code and Catching Exceptions (continued) Java Programming, Fifth Edition

Trying Code and Catching Exceptions (continued) If no Exception occurs within the try block catch block does not execute getMessage() method Obtain information about Exception Within catch block Might want to add code to correct the error Java Programming, Fifth Edition

Trying Code and Catching Exceptions (continued) Java Programming, Fifth Edition

Throwing and Catching Multiple Exceptions Can place multiple statements within try block Only first error-generating statement throws Exception Catch multiple Exceptions Examined in sequence Until match found for Exception type Matching catch block executes Each remaining catch block bypassed Java Programming, Fifth Edition

Java Programming, Fifth Edition

Throwing and Catching Multiple Exceptions (continued) “Catch-all” block Accepts more generic Exception argument type: catch(Exception e) Unreachable code Program statements that can never execute under any circumstances Poor style for method to throw more than three or four types Java Programming, Fifth Edition

Java Programming, Fifth Edition

Java Programming, Fifth Edition