Abstract Classes, Exceptions

Similar documents
Sept 26, 2016 Sprenkle - CSCI Documentation is a love letter that you write to your future self. Damian Conway

Review. Errors. Ø Users may enter data in the wrong form Ø Files may not exist Ø Program code has bugs!*

Object-Oriented Programming Design Topic : Exception Programming

CS 61B Data Structures and Programming Methodology. July 7, 2008 David Sun

Review: Collec-ons Framework

10/7/15. MediaItem tostring Method. Objec,ves. Using booleans in if statements. Review. Javadoc Guidelines

Object oriented programming. Instructor: Masoud Asghari Web page: Ch: 7

Errors and Exceptions

Assoc. Prof. Marenglen Biba. (C) 2010 Pearson Education, Inc. All rights reserved.

Lecture 20. Java Exceptional Event Handling. Dr. Martin O Connor CA166

Exceptions. References. Exceptions. Exceptional Conditions. CSE 413, Autumn 2005 Programming Languages

Exceptions. CSE 142, Summer 2002 Computer Programming 1.

Exceptions. Readings and References. Exceptions. Exceptional Conditions. Reading. CSE 142, Summer 2002 Computer Programming 1.

Exceptions. Errors and Exceptions. Dealing with exceptions. What to do about errors and exceptions

Day 8. COMP1006/1406 Summer M. Jason Hinek Carleton University

6.Introducing Classes 9. Exceptions

CISC370: Inheritance

Exception-Handling Overview

AP COMPUTER SCIENCE JAVA CONCEPTS IV: RESERVED WORDS

CSC207H: Software Design. Exceptions. CSC207 Winter 2018

Exceptions and Libraries

CS 3 Introduction to Software Engineering. 3: Exceptions

A Third Look At Java. Chapter Seventeen Modern Programming Languages, 2nd ed. 1

Programming II (CS300)

Internal Classes and Exceptions

EXCEPTION HANDLING. Summer 2018

Exceptions. CSC207 Winter 2017

COMP1008 Exceptions. Runtime Error

Introduction Unit 4: Input, output and exceptions

A problem?... Exceptions. A problem?... A problem?... Suggested Reading: Bruce Eckel, Thinking in Java (Fourth Edition) Error Handling with Exceptions

BBM 102 Introduction to Programming II Spring Exceptions

PIC 20A Exceptions. Ernest Ryu UCLA Mathematics. Last edited: November 27, 2017

Comp 249 Programming Methodology Chapter 9 Exception Handling

On my Twitter feed: Sept 30, 2016 Sprenkle - CSCI public boolean equals(object o){ if(((birthday) o).getday()!= this.getday()) return false;

Check out FilesAndExceptions from SVN. Exam 2 Review File I/O, Exceptions Vector Graphics Project

What is the purpose of exceptions and exception handling? Vocabulary: throw/raise and catch/handle Exception propagation Java checked and unchecked

BBM 102 Introduction to Programming II Spring 2017

Correctness and Robustness

CS193j, Stanford Handout #25. Exceptions

Objec-ves JAR FILES. Jar files. Excep-ons. Files Streams. Ø Wrap up Ø Why Excep-ons? 9/30/16. Oct 3, 2016 Sprenkle - CSCI209 1

Full file at Chapter 2 - Inheritance and Exception Handling

EXCEPTIONS. Objectives. The try and catch Statements. Define exceptions. Use try, catch and finally statements. Describe exception categories

EXCEPTIONS. Java Programming

Chapter 13 Exception Handling

CS112 Lecture: Exceptions. Objectives: 1. Introduce the concepts of program robustness and reliability 2. Introduce exceptions

ITI Introduction to Computing II

Exception Handling. Sometimes when the computer tries to execute a statement something goes wrong:

Java Primer. CITS2200 Data Structures and Algorithms. Topic 2

1 Shyam sir JAVA Notes

Exceptions and Error Handling

Exception Handling. Run-time Errors. Methods Failure. Sometimes when the computer tries to execute a statement something goes wrong:

Exception Handling. General idea Checked vs. unchecked exceptions Semantics of... Example from text: DataAnalyzer.

16-Dec-10. Consider the following method:

More on Objects in JAVA TM

Program Correctness and Efficiency. Chapter 2

CS/ENGRD 2110 FALL Lecture 7: Interfaces and Abstract Classes

Java Loose Ends. 11 December 2017 OSU CSE 1

COP 3330 Final Exam Review

ITI Introduction to Computing II

Exceptions, try - catch - finally, throws keyword. JAVA Standard Edition

Good Coding Practices Spring 2018

CSC System Development with Java. Exception Handling. Department of Statistics and Computer Science. Budditha Hettige

CS/ENGRD 2110 SPRING Lecture 7: Interfaces and Abstract Classes

Programming II (CS300)

Lecture 19 Programming Exceptions CSE11 Fall 2013

Exceptions. Produced by. Algorithms. Eamonn de Leastar Department of Computing, Maths & Physics Waterford Institute of Technology

Outline. Java Models for variables Types and type checking, type safety Interpretation vs. compilation. Reasoning about code. CSCI 2600 Spring

Chapter 9. Exception Handling. Copyright 2016 Pearson Inc. All rights reserved.

School of Informatics, University of Edinburgh

Exceptions. Produced by. Introduction to the Java Programming Language. Eamonn de Leastar

Programming in Java

Exception Handling Introduction. Error-Prevention Tip 13.1 OBJECTIVES

Administration. Exceptions. Leftovers. Agenda. When Things Go Wrong. Handling Errors. CS 99 Summer 2000 Michael Clarkson Lecture 11

COMP200 EXCEPTIONS. OOP using Java, based on slides by Shayan Javed

Introduction to Programming Using Java (98-388)

CS 231 Data Structures and Algorithms, Fall 2016

More on Exception Handling

CS 11 java track: lecture 3

More on Exception Handling

Fundamentals of Object Oriented Programming

Input, Output and Exceptions. COMS W1007 Introduction to Computer Science. Christopher Conway 24 June 2003

Exceptions. Examples of code which shows the syntax and all that

Exceptions in Java

OBJECT ORIENTED PROGRAMMING. Course 6 Loredana STANCIU Room B616

Checked and Unchecked Exceptions in Java

Defensive Programming. Ric Glassey

CS112 Lecture: Exceptions and Assertions

CS 61B Discussion 5: Inheritance II Fall 2014

Exceptions vs. Errors Exceptions vs. RuntimeExceptions try...catch...finally throw and throws

Data Structures. 02 Exception Handling

CSCI Object Oriented Design: Java Review Errors George Blankenship. Java Review - Errors George Blankenship 1

CSCI Object-Oriented Design. Java Review Topics. Program Errors. George Blankenship 1. Java Review Errors George Blankenship

COMP-202 Unit 9: Exceptions

Sri Vidya College of Engineering & Technology Question Bank

Exceptions. Computer Science and Engineering College of Engineering The Ohio State University. Lecture 15

CS260 Intro to Java & Android 03.Java Language Basics

COMP 213. Advanced Object-oriented Programming. Lecture 17. Exceptions

ECE 122. Engineering Problem Solving with Java

Weiss Chapter 1 terminology (parenthesized numbers are page numbers)

Writing your own Exceptions. How to extend Exception

Transcription:

CISC 370: Inheritance, Abstract Classes, Exceptions June 15, 1 2006 1 Review Quizzes Grades on CPM Conventions Class names are capitalized Object names/variables are lower case String.doStuff dostuff(); string.dostuff dostuff(); Encapsulation Inheritance Packages Sara Sprenkle - CISC370 2 1

Encapsulation Hide implementation details can change the implementation details without programmer's relying on it Protect against accidental or willful stupidity may have interdependent fields can't modify one field without updating the others to keep in a consistent state --> method can do all necessary steps Sara Sprenkle - CISC370 3 Encapsulation If fields can be manipulated directly, the number of possibilities you have to test becomes unmanageable What could the user do? Can use methods to perform error checking What if user set chicken to have a negative height? Internal fields and methods visible outside the class clutter up API makes class tidy and easier to use and understand Sara Sprenkle - CISC370 4 2

Inheritance Build new classes based on existing classes Allows you to reuse code Use extends keyword to make a subclass The is a relationship Classic mark of inheritance Constructor chaining Sara Sprenkle - CISC370 5 Inheritance Access modifiers in subclasses can make access to subclass more restrictive but not less restrictive Class fields and methods are not inherited Constructors are not inherited We had to define Rooster( String name, int height, double weight) event though similar constructor in Chicken Sara Sprenkle - CISC370 6 3

Inheritance If you're uncertain which to use (protected, package, or private), use the most restrictive Changing to less restrictive is easy Changing to more restrictive may break the code that uses your classes. Sara Sprenkle - CISC370 7 Member Visibility Accessible to Defining Class Class in same package Subclass in different package Non-subclass different package Public Yes Yes Yes Yes Member Visibility Protected Yes Yes Yes No Package Yes Yes No No Private Yes No No No Sara Sprenkle - CISC370 8 4

Protected Accessible to subclasses and members of package Can t t keep encapsulation pure Don t t want others to access fields directly May break code if you change your implementation Assumption? someone extending your class with protected access knows about what they are doing Sara Sprenkle - CISC370 9 Packages Hierarchical structure of Java classes Directories of directories java lang net util Object Date Fully qualified name: java.util.date Use import to access packages Sara Sprenkle - CISC370 10 5

Abstract Classes Some methods defined, others not defined Classes in which not all methods are implemented are abstract classes. public abstract class ZooAnimal Blank methods are labeled with the abstract keyword also public abstract void exercise(); Sara Sprenkle - CISC370 11 Abstract Classes An abstract class cannot be instantiated Subclass of an abstract class can only be instantiated if it overrides each of the abstract methods of its superclass and provides implementation If subclass does not override all abstract methods, it is also abstract Sara Sprenkle - CISC370 12 6

Abstract Classes static, private, and final methods cannot be abstract these types cannot be overridden by a subclass a final class cannot contain any abstract methods a class can be declared abstract even if it does not actually have any abstract methods the implementation is somehow incomplete and is meant to serve as a superclass for one or more subclasses that will complete the implementation. Sara Sprenkle - CISC370 13 Abstract Classes Can have an array of objects of the abstract class does dynamic dispatch on them Use abstract when have some partial implementation Sara Sprenkle - CISC370 14 7

Examples of abstract classes Define the abstract methods Example 1: java.net.socket java.net.sslsocket (abstract) Example 2: java.util util.calendar (abstract) java.util util.gregoriancalendar Sara Sprenkle - CISC370 15 Interfaces Like abstract classes with only abstract methods A set of requirements for classes to conform to Pure specification, no implementation Classes implement one or more interfaces. Sara Sprenkle - CISC370 16 8

Example of an Interface We have seen before how to make an array of Chicken object variables. We can call the Arrays.sort() method, a method of the Arrays class Arrays.sort() has the ability to sort arrays of any object class. Need a way to decide if one object is less than, greater than, or equal to another object. Class of objects must be comparable. Comparable is an interface Sara Sprenkle - CISC370 17 java.lang lang.comparable public interface Comparable int compareto(object other); Any object that is Comparable must have a method named compareto(), which takes an Object as a parameter and returns an integer < 0 for less than 0 for equals > 0 for greater than Sara Sprenkle - CISC370 18 9

Implementing an Interface To make a class implement an interface In the class definition, you need to specify that the class will implement the specific interface. You provide a definition for all of the methods specified in the interface. An interface is very similar to an abstract (or virtual) class in C++ a set of requirements that any implementing class must have Sara Sprenkle - CISC370 19 How to determine Chicken order? What if made the Chicken class Comparable? Sara Sprenkle - CISC370 20 10

Comparable Chickens class Chicken implements Comparable... public int compareto(object otherobject) Chicken other = (Chicken)otherObject; if (height < other.getheight() ) return 1; if (height > other.getheight()) return 1; return 0; One way: order by height What if otherobject is not a Chicken? Sara Sprenkle - CISC370 21 Comparable Chickens class Chicken implements Comparable... public int compareto(object otherobject) Chicken other = (Chicken)otherObject; if (height < other.getheight() ) return 1; if (height > other.getheight()) return 1; if( weight < other.getweight()) return -1; if (weight > other.getweight()) return 1; return 0; Order by height, then weight Could have more conditions for breaking ties --> comparing names Sara Sprenkle - CISC370 22 11

Comparable Interface in Java Docs API documentation says what the compareto() method should do: Return a 11 if the first object is less than the second object (passed as a parameter) Return a 1 if the second object (passed as a parameter) is less than the first object Return a 0 if the two objects are equal Can see what Java library classes implement Comparable Sara Sprenkle - CISC370 23 Interfaces only object (not class) methods all are public methods implied if not explicit error to have protected or private (Why( Why?) fields are constants that are static and final Can implement multiple interfaces separated by commas in definition Sara Sprenkle - CISC370 24 12

Testing for Interfaces We can also use the instanceof operator to see if an object implements a particular interface e.g., to determine if an object can be compared to another object using the Comparable interface. if (obj instanceof Comparable) // runs if whatever class obj is an instance of // implements the Comparable interface else // runs if it does not implement the interface Sara Sprenkle - CISC370 25 Interface Object Variables We can use an object variable to refer to an object of any class that implements an interface Using this object variable, we can only access methods that are present in the interface. For example Object obj; if (obj instanceof Comparable) Comparable comp = (Comparable)obj; boolean res = comp.compareto(obj2); Sara Sprenkle - CISC370 26 13

Interface Definitions public interface Comparable int compareto(object other); We do not need to specify the methods as public All interface methods are public by default Sara Sprenkle - CISC370 27 Interface Definitions and Inheritance We can also extend interfaces allows a chain of interfaces that go from general to more specific with each step For example, let s s define an interface for a object which is capable of moving: public interface Movable void move(double x, double y); Sara Sprenkle - CISC370 28 14

Interface Definitions and Inheritance A powered vehicle is also Movable it must also have a MPG() method, which will return its gas mileage public interface Powered extends Movable double miles_per_gallon(); Sara Sprenkle - CISC370 29 Constants in an Interface If a variable is specified in an interface, it is automatically a constant public static final variable public interface Powered extends Movable double miles_per_gallon(); double SPEED_LIMIT = 95; An object that implements the Powered interface has a constant SPEED_LIMIT defined Sara Sprenkle - CISC370 30 15

Interface Definitions and Inheritance Powered interface extends the Movable interface. Any object that implements the Powered interface must satisfy all the requirements of that interface as well as its superinterface. A Powered object must have a miles_per_gallon() and move() method Sara Sprenkle - CISC370 31 Multiple Interfaces A class can implement multiple interfaces An interface is a promise to implement given methods Can have more than one interface and fulfill the requirements of each one. But, NOT possible with inheritance a class can only extend (or inherit from) one class. public final class String implements Serializable, Comparable, CharSequence Sara Sprenkle - CISC370 32 16

Using Interfaces Common use: define constants for multiple classes/package Something like global constants Marker Interface Interface that is empty Use to identify an object that has a certain property Sara Sprenkle - CISC370 33 Using interface or abstract class? Interfaces Any class can use (can implement multiple interfaces) no implementation Implementing lots of methods multiple times can be annoying Adding a method will break classes that implement Abstract class Can contain partial implementation Can t t extend/subclass multiple classes Can add non-abstract methods without breaking subclasses Sara Sprenkle - CISC370 34 17

One option: Use Both! Define interface, e.g., MyInterface Define abstract class, e.g., AbstractMyInterface implements interface provides implementation for some methods Sara Sprenkle - CISC370 35 Exceptions Sara Sprenkle - CISC370 36 18

Errors Programs encounter errors when they run. Users may enter data in the wrong form files that should exist sometimes do not printers run out of paper in the middle of printing program code always has bugs. Errors are bad. When one happens, your program should do one of two things: Revert to a stable state and continue. Allow the user to save data and then exit the program gracefully. Sara Sprenkle - CISC370 37 Error Codes Why They Don t Always Work The traditional method of indicating an error in a method (function) call is to return a specific sentinel value. the read() function in C returns a 11 if the read was unsuccessful What is the general problem with sentinels? What does a function that returns an integer return in the case of an error? It is not always possible to return an error code, when an error has occurred in a method. Sara Sprenkle - CISC370 38 19

Methods: An Alternate Ending Java allows a method to take an alternate exit path if it is unable to complete its task in the normal, correct way. A method can opt to not return a value. Instead it throws an object that encapsulates the error information. Exception: : the object that is thrown A method can return its specified return type (the normal/correct case) or it can throw an exception (the error case). Sara Sprenkle - CISC370 39 Methods: An Alternate Ending If a method throws an exception it does not return anything execution does not resume immediately following the method call (as it would if the method returns a normal value) JVM s exception-handling mechanism searches for an exception handler Exception handler: : error recovery code runs to deal with a particular error condition. Sara Sprenkle - CISC370 40 20

Exception Classification All exceptions indirectly derive from a class Throwable. Subclasses: : Error and Exception Important Throwable methods getmessage Detailed message about error printstacktrace Prints out where problem occurred and path to reach that point Also getstacktrace to get the stack in non-text format Sara Sprenkle - CISC370 41 Exception Classification: Error Error is an internal error JVM-generated in the case of resource exhaustion or an internal problem Out of Memory error (When( can that happen?) Program s s code should not and can not throw an object of this type. Unchecked exception Sara Sprenkle - CISC370 42 21

Exception Classification An Exception is the kind of Throwable objects programs deal with. RuntimeException something that happens due to a programming error you made Unchecked exception ArrayOutOfBoundsException NullPointerException ClassCastException Lots of checked exceptions e.g., IOException, SQLException Seen before Sara Sprenkle - CISC370 43 Exception Classification So, if something is programmer s s fault RuntimeException. otherwise, an Error or another Exception. Common: IOException trying to read past the end of a file trying to open a bad URL File not found etc Sara Sprenkle - CISC370 44 22

Exception Classification Throwable Error Exception IOException RuntimeException SQLException Sara Sprenkle - CISC370 45 Checked and Unchecked Unchecked: : any exception that derives from Error or RuntimeException Checked: : any other exception, e.g., from IOException Programmer need to create and handle checked exceptions not unchecked exceptions (except to try to make sure that they don t t occur in the first place!) Sara Sprenkle - CISC370 46 23

Unchecked Exceptions Two types of unchecked exceptions: Derived from the class Error: Any line of code in a Java program can generate this because it is internal You don t t need to worry about what to do if this happens. Derived from the class RuntimeException Indicates a bug in the program Don t t worry about what to do if it happens fix the bug! Sara Sprenkle - CISC370 47 Checked Exceptions Need to be handled in your program Advertise the exceptions that a particular method throws For each method, tell the compiler: what the method returns what could possibly go wrong As an example, java.io io.bufferedreader Sara Sprenkle - CISC370 48 24

The BufferedReader Class contains a method, readline(), which reads a line from a stream, such as a file or network connection Its header looks like: public String readline() throws IOException readline can return a String (if everything went right) throw an IOException (if something went wrong) Sara Sprenkle - CISC370 49 Programmer-Defined Methods Advertise only the checked methods that your method can throw Your method calls a method that throws a checked exception Your method detects an error in its processing and decides to throw an exception Sara Sprenkle - CISC370 50 25

Passing an Exception Up So, if we were to write a method which calls the readline() method of a BufferedReader: String readdata(bufferedreader in) throws IOException String str1; str1 = in.readline(); return str1; Sara Sprenkle - CISC370 51 Passing an Exception Up String readdata(bufferedreader in) throws IOException String str1; Throws the IOException str1 = in.readline(); return str1; Our readdata() method calls a method that can throw an IOException readline() will throw this exception to us Assuming we don t t want to deal with exceptions, we simply throw the exception as well whoever called readdata will handle exception Sara Sprenkle - CISC370 52 26

Throwing Our Own Exception If we have a program which is reading a file byte-by-byte. We know in advance how big this file is supposed to be. What do we do if we reach an EOF byte while we should still have data to read in? We need to generate our own exception. Sara Sprenkle - CISC370 53 Throwing Our Own Exception For example String readbytes(bufferedreader in, int num_bytes) throws EOFException while (...) if (char_in == EOF) if (number_read < num_bytes) throw new EOFException();...... Fibanacci.java Sara Sprenkle - CISC370 54 27

Throwing Our Own Exception if (num_read < num_bytes) throw new EOFException(); If we encounter an EOF, we make a new object of class EOFException class derived from IOException After making exception object, we throw it The method ends at this point The calling program needs to deal with our exception, which tells it that we encountered an EOF before we should have. Sara Sprenkle - CISC370 55 A More Descriptive Exception There are actually two constructors for all Exception classes default (no parameters) one that takes a String describe the condition that generated this exception more fully if (num_read < num_bytes) String gripe = I read + num_read + when I should have read + num_bytes; throw new EOFException(gripe); Sara Sprenkle - CISC370 56 28

Creating Our Own Exception Class The EOFException class described the error our method encountered well. not always the case. Many exceptions derived from IOException,, but plenty more conditions. What do you do when you cannot find a predefined exception class the describes your condition? Make a new exception class! Sara Sprenkle - CISC370 57 Creating Our Own Exception Class public class FileFormatException extends IOException public FileFormatException() public FileFormatException(String gripe) super(gripe); Now, we are ready to throw exceptions of type FileFormatException Sara Sprenkle - CISC370 58 29

Catching Exceptions After we throw an exception, some part of our program needs to catch it some part of our program knows how to deal with the situation that caused the exception receives it handles the problem Hopefully gracefully, without exiting Sara Sprenkle - CISC370 59 The try/catch Block The simplest way to catch an exception is to use a try/catch block Simplest form of this block looks like: try code; more code; catch (ExceptionType e) error code for ExceptionType Sara Sprenkle - CISC370 60 30

Try/Catch Block The code in the try block runs first If it completes without an exception, the catch block(s) are skipped If the try code generates an exception, a catch block runs remaining code in the try block is skipped. Sara Sprenkle - CISC370 61 The try/catch Block try code; more code; catch (ExceptionType e) error code for ExceptionType If the code inside the try block does not throw an exception of ExceptionType, the catch block is skipped. If an exception of a type other than ExceptionType is thrown inside the try block, the method exits immediately and the program dies. Sara Sprenkle - CISC370 62 31

The try/catch Block try code; more code; catch (ExceptionType1 e) error code for ExceptionType catch (ExceptionType2 e) error code for ExceptionType Can catch any type with Exception e, but won t have customized messages You can have more than one catch block. lets you handle more than one type of exception that can be thrown inside your try block. If ExceptionType1 does not catch the exception, it falls to ExceptionType2, and so forth run the first matching catch block. Sara Sprenkle - CISC370 63 try/catch an Example public void read(bufferedreader in) try boolean done = false; while (!done) String line=in.readline(); // this could throw IOException! if (line == null) done = true; catch (IOException exp) exp.printstacktrace(); Prints out stack trace to method call that caused the error Sara Sprenkle - CISC370 64 32

try/catch an Example public void read(bufferedreader in) boolean done = false; while (!done) try String line=in.readline(); // this could throw IOException! if (line == null) done = true; catch (IOException exp) exp.printstacktrace(); More precise try/catch may help pinpoint error But could result in messier code Sara Sprenkle - CISC370 65 The finally Block Can add a finally block after all possible catch blocks Code in finally block always runs, after the code in the try and/or catch blocks after the try block finishes, or if an exception occurs, after the catch block finishes. Allows you to clean up or do maintenance before the method ends (one way or the other) E.g., closing database connections Sara Sprenkle - CISC370 66 33

The try/catch/finally Blocks try statement1; statement2; catch (EOFException e) statement3; statement4; finally statement5; statement6; Which statements run if: Neither statement 1 nor statement 2 throws an exception Statement 1 throws an EOFException Statement 2 throws an EOFException Statement 1 throws an IOException Sara Sprenkle - CISC370 67 What to do with a Caught Exception? We dump the stack after the exception occurs What else can we do? Often, the best answer is to do nothing but report the problem If an exception occurs in the readline() method, our read() method should probably pass up to whoever called it Instead of catching this exception, simply advertise that the read() method can throw an IOException. Let whoever calls the read() method catch and handle the exception. Sara Sprenkle - CISC370 68 34

A Further Example public void read(bufferedreader in) throws IOException boolean done = false; while (!done) String line=in.readline(); // this could throw IOException! if (line == null) done = true; Sara Sprenkle - CISC370 69 Checked Exceptions Why are these called checked exceptions? the compiler checks to make sure you deal with such an exception. If you call a method that could generate a checked exception, you can either catch and handle it, or have your method throw the exception up to whoever called it by advertising the exception You MUST do one of these two things Sara Sprenkle - CISC370 70 35

Methods Throwing Exceptions The online API documentation will tell you if a method can throw an exception. If so, you must handle it If your method could possibly throw an exception (by generating it or by calling another method that could), advertise it! If you can t t handle all sorts of errors, that s OK let whoever is calling you worry about it. However, they can only do that if you advertise any exceptions you can t t deal with. Sara Sprenkle - CISC370 71 Programming with Exceptions Exception handling is slow Use one big try block instead of nesting try- catch blocks too deep Don't ignore exceptions it's better to pass them along to higher calls Sara Sprenkle - CISC370 72 36

Benefits of exceptions? Sara Sprenkle - CISC370 73 Benefits of Exceptions Force error checking/handling Otherwise, won t t compile Does not guarantee good exception handling Ease debugging Stack trace Sara Sprenkle - CISC370 74 37