Chapter 12 Exception Handling And Text IO

2y ago
3 Views
3 Downloads
1.24 MB
64 Pages
Last View : 1m ago
Last Download : 3m ago
Upload by : Allyson Cromer
Transcription

Chapter 12 Exception Handlingand Text IOLiang, Introduction to Java Programming, Tenth Edition, (c) 2015 Pearson Education, Inc. Allrights reserved.1

MotivationsWhen a program runs into a runtime error, theprogram terminates abnormally. How can youhandle the runtime error so that the program cancontinue to run or terminate gracefully? This is thesubject we will introduce in this chapter.Liang, Introduction to Java Programming, Tenth Edition, (c) 2015 Pearson Education, Inc. Allrights reserved.2

ObjectivesTo get an overview of exceptions and exception handling (§12.2).To explore the advantages of using exception handling (§12.2).To distinguish exception types: Error (fatal) vs. Exception (nonfatal) and checked vs. unchecked (§12.3).To declare exceptions in a method header (§12.4.1).To throw exceptions in a method (§12.4.2).To write a try-catch block to handle exceptions (§12.4.3).To explain how an exception is propagated (§12.4.3).To obtain information from an exception object (§12.4.4).To develop applications with exception handling (§12.4.5).To use the finally clause in a try-catch block (§12.5).To use exceptions only for unexpected errors (§12.6).To rethrow exceptions in a catch block (§12.7).To create chained exceptions (§12.8).To define custom exception classes (§12.9).To discover file/directory properties, to delete and rename files/directories, and to create directories using theFile class (§12.10).To write data to a file using the PrintWriter class (§12.11.1).To use try-with-resources to ensure that the resources are closed automatically (§12.11.2).To read data from a file using the Scanner class (§12.11.3).To understand how data is read using a Scanner (§12.11.4).To develop a program that replaces text in a file (§12.11.5).To read data from the Web (§12.12).To develop a Web crawler (§12.13).Liang, Introduction to Java Programming, Tenth Edition, (c) 2015 Pearson Education, Inc. All3rights reserved.

Exception-Handling OverviewShow runtime errorQuotientRunFix it using an if statementQuotientWithIfRunWith a methodQuotientWithMethodRunLiang, Introduction to Java Programming, Tenth Edition, (c) 2015 Pearson Education, Inc. Allrights reserved.4

Exception AdvantagesQuotientWithExceptionRunNow you see the advantages of using exception handling.It enables a method to throw an exception to its caller.Without this capability, a method must handle theexception or terminate the program.Liang, Introduction to Java Programming, Tenth Edition, (c) 2015 Pearson Education, Inc. Allrights reserved.5

Handling nBy handling InputMismatchException, your program willcontinuously read an input until it is correct.Liang, Introduction to Java Programming, Tenth Edition, (c) 2015 Pearson Education, Inc. Allrights reserved.6

Exception onIndexOutOfBoundsExceptionMany more classesObjectIllegalArgumentExceptionThrowableMany more classesLinkageErrorErrorVirtualMachineErrorMany more classesLiang, Introduction to Java Programming, Tenth Edition, (c) 2015 Pearson Education, Inc. Allrights reserved.7

System ionIndexOutOfBoundsExceptionMany more em errors are thrown by JVMand represented in the Error class.The Error class describes internalsystem errors. Such errors rarelyoccur. If one does, there is littleyou can do beyond notifying theuser and trying to terminate theprogram gracefully.Many more classesLinkageErrorErrorVirtualMachineErrorMany more classesLiang, Introduction to Java Programming, Tenth Edition, (c) 2015 Pearson Education, Inc. Allrights reserved.8

ExceptionsException describes errorscaused by your programand externalcircumstances. Theseerrors can be caught andhandled by your ptionIndexOutOfBoundsExceptionMany more classesObjectIllegalArgumentExceptionThrowableMany more classesLinkageErrorErrorVirtualMachineErrorMany more classesLiang, Introduction to Java Programming, Tenth Edition, (c) 2015 Pearson Education, Inc. Allrights reserved.9

Runtime ceptionIndexOutOfBoundsExceptionMany more classesObjectIllegalArgumentExceptionThrowableMany more Exception is caused byprogramming errors, such as badcasting, accessing an out-of-boundsarray, and numeric errors.Many more classesLiang, Introduction to Java Programming, Tenth Edition, (c) 2015 Pearson Education, Inc. Allrights reserved.10

Checked Exceptions vs.Unchecked ExceptionsRuntimeException, Error and their subclasses areknown as unchecked exceptions. All otherexceptions are known as checked exceptions,meaning that the compiler forces the programmerto check and deal with the exceptions.Liang, Introduction to Java Programming, Tenth Edition, (c) 2015 Pearson Education, Inc. Allrights reserved.11

Unchecked ExceptionsIn most cases, unchecked exceptions reflect programminglogic errors that are not recoverable. For example, aNullPointerException is thrown if you access an objectthrough a reference variable before an object is assigned toit; an IndexOutOfBoundsException is thrown if you accessan element in an array outside the bounds of the array.These are the logic errors that should be corrected in theprogram. Unchecked exceptions can occur anywhere in theprogram. To avoid cumbersome overuse of try-catchblocks, Java does not mandate you to write code to catchunchecked exceptions.Liang, Introduction to Java Programming, Tenth Edition, (c) 2015 Pearson Education, Inc. Allrights reserved.12

Unchecked ceptionIndexOutOfBoundsExceptionMany more classesObjectIllegalArgumentExceptionThrowableMany more edexception.Many more classesLiang, Introduction to Java Programming, Tenth Edition, (c) 2015 Pearson Education, Inc. Allrights reserved.13

Declaring, Throwing, andCatching Exceptionsdeclare exceptionmethod1() {method2() throws Exception {try {invoke method2;}catch (Exception ex) {Process exception;}catch exceptionif (an error occurs) {throw new Exception();}throw exception}}Liang, Introduction to Java Programming, Tenth Edition, (c) 2015 Pearson Education, Inc. Allrights reserved.14

Declaring ExceptionsEvery method must state the types of checkedexceptions it might throw. This is known asdeclaring exceptions.public void myMethod()throws IOExceptionpublic void myMethod()throws IOException, OtherExceptionLiang, Introduction to Java Programming, Tenth Edition, (c) 2015 Pearson Education, Inc. Allrights reserved.15

Throwing ExceptionsWhen the program detects an error, the programcan create an instance of an appropriate exceptiontype and throw it. This is known as throwing anexception. Here is an example,throw new TheException();TheException ex new TheException();throw ex;Liang, Introduction to Java Programming, Tenth Edition, (c) 2015 Pearson Education, Inc. Allrights reserved.16

Throwing Exceptions Example/** Set a new radius */public void setRadius(double newRadius)throws IllegalArgumentException {if (newRadius 0)radius newRadius;elsethrow new IllegalArgumentException("Radius cannot be negative");}Liang, Introduction to Java Programming, Tenth Edition, (c) 2015 Pearson Education, Inc. Allrights reserved.17

Catching Exceptionstry {statements; // Statements that may throw exceptions}catch (Exception1 exVar1) {handler for exception1;}catch (Exception2 exVar2) {handler for exception2;}.catch (ExceptionN exVar3) {handler for exceptionN;}Liang, Introduction to Java Programming, Tenth Edition, (c) 2015 Pearson Education, Inc. Allrights reserved.18

Catching Exceptionsmain method {.try {.invoke method1;statement1;}catch (Exception1 ex1) {Process ex1;}statement2;}method1 {.try {.invoke method2;statement3;}catch (Exception2 ex2) {Process ex2;}statement4;}method2 {.try {.invoke method3;statement5;}catch (Exception3 ex3) {Process ex3;}statement6;}An exceptionis thrown inmethod3Call Stackmethod3main methodmethod2method2method1method1method1main methodmain methodmain methodLiang, Introduction to Java Programming, Tenth Edition, (c) 2015 Pearson Education, Inc. Allrights reserved.19

Catch or Declare Checked ExceptionsSuppose p2 is defined as follows:void p2() throws IOException {if (a file does not exist) {throw new IOException("File does not exist");}.}Liang, Introduction to Java Programming, Tenth Edition, (c) 2015 Pearson Education, Inc. Allrights reserved.20

Catch or Declare Checked ExceptionsJava forces you to deal with checked exceptions. If a method declares achecked exception (i.e., an exception other than Error orRuntimeException), you must invoke it in a try-catch block or declare tothrow the exception in the calling method. For example, suppose thatmethod p1 invokes method p2 and p2 may throw a checked exception (e.g.,IOException), you have to write the code as shown in (a) or (b).void p1() {try {p2();}catch (IOException ex) {.}}(a)void p1() throws IOException {p2();}(b)Liang, Introduction to Java Programming, Tenth Edition, (c) 2015 Pearson Education, Inc. Allrights reserved.21

Example: Declaring, Throwing, andCatching ExceptionsObjective: This example demonstratesdeclaring, throwing, and catching exceptionsby modifying the setRadius method in theCircle class defined in Chapter 8. The newsetRadius method throws an exception ifradius is nRunLiang, Introduction to Java Programming, Tenth Edition, (c) 2015 Pearson Education, Inc. Allrights reserved.22

Rethrowing Exceptionstry {statements;}catch(TheException ex) {perform operations before exits;throw ex;}Liang, Introduction to Java Programming, Tenth Edition, (c) 2015 Pearson Education, Inc. Allrights reserved.23

The finally Clausetry {statements;}catch(TheException ex) {handling ex;}finally {finalStatements;}Liang, Introduction to Java Programming, Tenth Edition, (c) 2015 Pearson Education, Inc. Allrights reserved.24

animationTrace a Program ExecutionSuppose noexceptions in thestatementstry {statements;}catch(TheException ex) {handling ex;}finally {finalStatements;}Next statement;Liang, Introduction to Java Programming, Tenth Edition, (c) 2015 Pearson Education, Inc. Allrights reserved.25

animationTrace a Program Executiontry {statements;}catch(TheException ex) {handling ex;}finally {finalStatements;}The final block isalways executedNext statement;Liang, Introduction to Java Programming, Tenth Edition, (c) 2015 Pearson Education, Inc. Allrights reserved.26

animationTrace a Program Executiontry {statements;}catch(TheException ex) {handling ex;}finally {finalStatements;}Next statement in themethod is executedNext statement;Liang, Introduction to Java Programming, Tenth Edition, (c) 2015 Pearson Education, Inc. Allrights reserved.27

animationTrace a Program Executiontry 1 ex) {handling ex;}finally {finalStatements;}Suppose an exceptionof type Exception1 isthrown in statement2Next statement;Liang, Introduction to Java Programming, Tenth Edition, (c) 2015 Pearson Education, Inc. Allrights reserved.28

animationTrace a Program Executiontry 1 ex) {handling ex;}finally {finalStatements;}The exception ishandled.Next statement;Liang, Introduction to Java Programming, Tenth Edition, (c) 2015 Pearson Education, Inc. Allrights reserved.29

animationTrace a Program Executiontry 1 ex) {handling ex;}finally {finalStatements;}The final block isalways executed.Next statement;Liang, Introduction to Java Programming, Tenth Edition, (c) 2015 Pearson Education, Inc. Allrights reserved.30

animationTrace a Program Executiontry 1 ex) {handling ex;}finally {finalStatements;}The next statement inthe method is nowexecuted.Next statement;Liang, Introduction to Java Programming, Tenth Edition, (c) 2015 Pearson Education, Inc. Allrights reserved.31

animationTrace a Program Executiontry 1 ex) {handling ex;}catch(Exception2 ex) {handling ex;throw ex;}finally {finalStatements;}statement2 throws anexception of typeException2.Next statement;Liang, Introduction to Java Programming, Tenth Edition, (c) 2015 Pearson Education, Inc. Allrights reserved.32

animationTrace a Program Executiontry 1 ex) {handling ex;}catch(Exception2 ex) {handling ex;throw ex;}finally {finalStatements;}Handling exceptionNext statement;Liang, Introduction to Java Programming, Tenth Edition, (c) 2015 Pearson Education, Inc. Allrights reserved.33

animationTrace a Program Executiontry 1 ex) {handling ex;}catch(Exception2 ex) {handling ex;throw ex;}finally {finalStatements;}Execute the final blockNext statement;Liang, Introduction to Java Programming, Tenth Edition, (c) 2015 Pearson Education, Inc. Allrights reserved.34

animationTrace a Program Executiontry 1 ex) {handling ex;}catch(Exception2 ex) {handling ex;throw ex;}finally {finalStatements;}Rethrow the exceptionand control istransferred to the callerNext statement;Liang, Introduction to Java Programming, Tenth Edition, (c) 2015 Pearson Education, Inc. Allrights reserved.35

Cautions When Using ExceptionsException handling separates error-handlingcode from normal programming tasks, thusmaking programs easier to read and to modify.Be aware, however, that exception handlingusually requires more time and resourcesbecause it requires instantiating a new exceptionobject, rolling back the call stack, andpropagating the errors to the calling methods.Liang, Introduction to Java Programming, Tenth Edition, (c) 2015 Pearson Education, Inc. Allrights reserved.36

When to Throw ExceptionsAn exception occurs in a method. If you wantthe exception to be processed by its caller, youshould create an exception object and throw it.If you can handle the exception in the methodwhere it occurs, there is no need to throw it.Liang, Introduction to Java Programming, Tenth Edition, (c) 2015 Pearson Education, Inc. Allrights reserved.37

When to Use ExceptionsWhen should you use the try-catch block in the code?You should use it to deal with unexpected errorconditions. Do not use it to deal with simple, expectedsituations. For example, the following codetry {System.out.println(refVar.toString());}catch (NullPointerException ex) {System.out.println("refVar is null");}Liang, Introduction to Java Programming, Tenth Edition, (c) 2015 Pearson Education, Inc. Allrights reserved.38

When to Use Exceptionsis better to be replaced byif (refVar ! tem.out.println("refVar is null");Liang, Introduction to Java Programming, Tenth Edition, (c) 2015 Pearson Education, Inc. Allrights reserved.39

Defining Custom Exception ClassesUse the exception classes in the API whenever possible.Define custom exception classes if the predefinedclasses are not sufficient.Define custom exception classes by extendingException or a subclass of Exception.Liang, Introduction to Java Programming, Tenth Edition, (c) 2015 Pearson Education, Inc. Allrights reserved.40

Custom Exception Class ExampleIn Listing 13.8, the setRadius method throws an exception if theradius is negative. Suppose you wish to pass the radius to thehandler, you have to create a custom exception ionTestCircleWithRadiusExceptionRunLiang, Introduction to Java Programming, Tenth Edition, (c) 2015 Pearson Education, Inc. Allrights reserved.41

CompanionWebsiteAssertionsAn assertion is a Java statement that enablesyou to assert an assumption about yourprogram. An assertion contains a Booleanexpression that should be true duringprogram execution. Assertions can be used toassure program correctness and avoid logicerrors.Liang, Introduction to Java Programming, Tenth Edition, (c) 2015 Pearson Education, Inc. Allrights reserved.42

CompanionWebsiteDeclaring AssertionsAn assertion is declared using the new Java keywordassert in JDK 1.4 as follows:assert assertion; orassert assertion : detailMessage;where assertion is a Boolean expression anddetailMessage is a primitive-type or an Object value.Liang, Introduction to Java Programming, Tenth Edition, (c) 2015 Pearson Education, Inc. Allrights reserved.43

CompanionWebsiteExecuting AssertionsWhen an assertion statement is executed, Java evaluates theassertion. If it is false, an AssertionError will be thrown. TheAssertionError class has a no-arg constructor and sevenoverloaded single-argument constructors of type int, long, float,double, boolean, char, and Object.For the first assert statement with no detail message, the no-argconstructor of AssertionError is used. For the second assertstatement with a detail message, an appropriate AssertionErrorconstructor is used to match the data type of the message. SinceAssertionError is a subclass of Error, when an assertion becomesfalse, the program displays a message on the console and exits.Liang, Introduction to Java Programming, Tenth Edition, (c) 2015 Pearson Education, Inc. Allrights reserved.44

CompanionWebsiteExecuting Assertions Examplepublic class AssertionDemo {public static void main(String[] args) {int i; int sum 0;for (i 0; i 10; i ) {sum i;}assert i 10;assert sum 10 && sum 5 * 10 : "sum is " sum;}}Liang, Introduction to Java Programming, Tenth Edition, (c) 2015 Pearson Education, Inc. Allrights reserved.45

CompanionWebsiteCompiling Programs withAssertionsSince assert is a new Java keyword introduced inJDK 1.4, you have to compile the program usinga JDK 1.4 compiler. Furthermore, you need toinclude the switch –source 1.4 in the compilercommand as follows:javac –source 1.4 AssertionDemo.javaNOTE: If you use JDK 1.5, there is no need touse the –source 1.4 option in the command.Liang, Introduction to Java Programming, Tenth Edition, (c) 2015 Pearson Education, Inc. Allrights reserved.46

CompanionWebsiteRunning Programs withAssertionsBy default, the assertions are disabled at runtime. Toenable it, use the switch –enableassertions, or –ea forshort, as follows:java –ea AssertionDemoAssertions can be selectively enabled or disabled atclass level or package level. The disable switch is –disableassertions or –da for short. For example, thefollowing command enables assertions in packagepackage1 and disables assertions in class Class1.java –ea:package1 –da:Class1 AssertionDemoLiang, Introduction to Java Programming, Tenth Edition, (c) 2015 Pearson Education, Inc. Allrights reserved.47

CompanionWebsiteUsing Exception Handling orAssertionsAssertion should not be used to replace exceptionhandling. Exception handling deals with unusualcircumstances during program execution. Assertions areto assure the correctness of the program. Exceptionhandling addresses robustness and assertion addressescorrectness. Like exception handling, assertions are notused for normal tests, but for internal consistency andvalidity checks. Assertions are checked at runtime andcan be turned on or off at startup time.Liang, Introduction to Java Programming, Tenth Edition, (c) 2015 Pearson Education, Inc. Allrights reserved.48

CompanionWebsiteUsing Exception Handling orAssertions, cont.Do not use assertions for argument checking in publicmethods. Valid arguments that may be passed to a publicmethod are considered to be part of the method’scontract. The contract must always be obeyed whetherassertions are enabled or disabled. For example, thefollowing code in the Circle class should be rewrittenusing exception handling.public void setRadius(double newRadius) {assert newRadius 0;radius newRadius;}Liang, Introduction to Java Programming, Tenth Edition, (c) 2015 Pearson Education, Inc. Allrights reserved.49

CompanionWebsiteUsing Exception Handling orAssertions, cont.Use assertions to reaffirm assumptions. This gives youmore confidence to assure correctness of the program. Acommon use of assertions is to replace assumptions withassertions in the code.Liang, Introduction to Java Programming, Tenth Edition, (c) 2015 Pearson Education, Inc. Allrights reserved.50

CompanionWebsiteUsing Exception Handling orAssertions, cont.Another good use of assertions is place assertions in aswitch statement without a default case. For example,switch (month) {case 1: . ; break;case 2: . ; break;.case 12: . ; break;default: assert false : "Invalid month: " month}Liang, Introduction to Java Programming, Tenth Edition, (c) 2015 Pearson Education, Inc. Allrights reserved.51

The File ClassThe File class is intended to provide an abstraction thatdeals with most of the machine-dependent complexitiesof files and path names in a machine-independentfashion. The filename is a string. The File class is awrapper class for the file name and its directory path.Liang, Introduction to Java Programming, Tenth Edition, (c) 2015 Pearson Education, Inc. Allrights reserved.52

Obtaining file properties and manipulating fileLiang, Introduction to Java Programming, Tenth Edition, (c) 2015 Pearson Education, Inc. Allrights reserved.53

Problem: Explore File PropertiesObjective: Write a program that demonstrates how tocreate files in a platform-independent way and use themethods in the File class to obtain their properties. Thefollowing figures show a sample run of the program onWindows and on Unix.TestFileClassLiang, Introduction to Java Programming, Tenth Edition, (c) 2015 Pearson Education, Inc. Allrights reserved.Run54

Text I/OA File object encapsulates the properties of a file or a path,but does not contain the methods for reading/writing datafrom/to a file. In order to perform I/O, you need to createobjects using appropriate Java I/O classes. The objectscontain the methods for reading/writing data from/to a file.This section introduces how to read/write strings andnumeric values from/to a text file using the Scanner andPrintWriter classes.Liang, Introduction to Java Programming, Tenth Edition, (c) 2015 Pearson Education, Inc. Allrights reserved.55

Writing Data Using PrintWriterjava.io.PrintWriter PrintWriter(filename: String)Creates a PrintWriter for the specified file. print(s: String): voidWrites a string. print(c: char): voidWrites a character. print(cArray: char[]): voidWrites an array of character. print(i: int): voidWrites an int value. print(l: long): voidWrites a long value. print(f: float): voidWrites a float value. print(d: double): voidWrites a double value. print(b: boolean): voidWrites a boolean value.Also contains the overloadedprintln methods.A println method acts like a print method; additionally itprints a line separator. The line separator string is definedby the system. It is \r\n on Windows and \n on Unix.The printf method was introduced in §3.6, “FormattingConsole Output and Strings.”Also contains the overloadedprintf methods.WriteDataLiang, Introduction to Java Programming, Tenth Edition, (c) 2015 Pearson Education, Inc. Allrights reserved.Run56

Try-with-resourcesProgrammers often forget to close the file. JDK 7 providesthe followings new try-with-resources syntax thatautomatically closes the files.try (declare and create resources) {Use the resource to process the file;}WriteDataWithAutoCloseRunLiang, Introduction to Java Programming, Tenth Edition, (c) 2015 Pearson Education, Inc. Allrights reserved.57

Reading Data Using Scannerjava.util.Scanner Scanner(source: File) Scanner(source: String)Creates a Scanner object to read data from the specified file.Creates a Scanner object to read data from the specified string. close() hasNext (): booleanClos es th is scanner.Returns true if this scanner has another token in its input. next(): StringReturns next token as a stri ng. nextByte(): byte nextShort(): shortReturns next token as a b yt e.Returns next token as a short. nextInt(): int nextLong(): longReturns next token as an int.Returns next token as a long. nextFloat(): floatReturns next token as a float. nextDouble(): double useDelimiter(pattern: String):ScannerReturns next token as a d ouble.Sets this scanner’s delimiting pattern.ReadDataLiang, Introduction to Java Programming, Tenth Edition, (c) 2015 Pearson Education, Inc. Allrights reserved.Run58

Problem: Replacing TextWrite a class named ReplaceText that replaces a string in a textfile with a new string. The filename and strings are passed ascommand-line arguments as follows:java ReplaceText sourceFile targetFile oldString newStringFor example, invokingjava ReplaceText FormatString.java t.txt StringBuilder StringBufferreplaces all the occurrences of StringBuilder by StringBuffer inFormatString.java and saves the new file in t.txt.ReplaceTextRunLiang, Introduction to Java Programming, Tenth Edition, (c) 2015 Pearson Education, Inc. Allrights reserved.59

Reading Data from the WebJust like you can read data from a file on yourcomputer, you can read data from a file on theWeb.Liang, Introduction to Java Programming, Tenth Edition, (c) 2015 Pearson Education, Inc. Allrights reserved.60

Reading Data from the WebURL url new URL("www.google.com/index.html");After a URL object is created, you can use theopenStream() method defined in the URL class to open aninput stream and use this stream to create a Scanner objectas follows:Scanner input new Scanner(url.openStream());ReadFileFromURLRunLiang, Introduction to Java Programming, Tenth Edition, (c) 2015 Pearson Education, Inc. Allrights reserved.61

Case Study: Web CrawlerThis case study develops a program that travels theWeb by following hyperlinks.Liang, Introduction to Java Programming, Tenth Edition, (c) 2015 Pearson Education, Inc. Allrights reserved.62

Case Study: Web CrawlerThe program follows the URLs to traverse the Web. Toavoid that each URL is traversed only once, the programmaintains two lists of URLs. One list stores the URLspending for traversing and the other stores the URLs thathave already been traversed. The algorithm for thisprogram can be described as follows:Liang, Introduction to Java Programming, Tenth Edition, (c) 2015 Pearson Education, Inc. Allrights reserved.63

Case Study: Web CrawlerAdd the starting URL to a list named listOfPendingURLs;while listOfPendingURLs is not empty {Remove a URL from listOfPendingURLs;if this URL is not in listOfTraversedURLs {Add it to listOfTraversedURLs;Display this URL;Exit the while loop when the size of S is equal to 100.Read the page from this URL and for each URL contained in the page {Add it to listOfPendingURLs if it is not is listOfTraversedURLs;}}}WebCrawlerRunLiang, Introduction to Java Programming, Tenth Edition, (c) 2015 Pearson Education, Inc. Allrights reserved.64

Liang, Introduction to Java Programming, Tenth Edition, (c) 2015 Pearson Education, Inc. All rig

Related Documents:

Part One: Heir of Ash Chapter 1 Chapter 2 Chapter 3 Chapter 4 Chapter 5 Chapter 6 Chapter 7 Chapter 8 Chapter 9 Chapter 10 Chapter 11 Chapter 12 Chapter 13 Chapter 14 Chapter 15 Chapter 16 Chapter 17 Chapter 18 Chapter 19 Chapter 20 Chapter 21 Chapter 22 Chapter 23 Chapter 24 Chapter 25 Chapter 26 Chapter 27 Chapter 28 Chapter 29 Chapter 30 .

A. Empirical studies on exception handling practices Prior research studied exception handling based on source code and issue trackers. Cabral and Marques [14] studied exception handling practices from 32 projects in both Java and.Net without considering the flow of exceptions. Prior work by Jo et al. [15] focuses on uncaught exceptions of .

TO KILL A MOCKINGBIRD. Contents Dedication Epigraph Part One Chapter 1 Chapter 2 Chapter 3 Chapter 4 Chapter 5 Chapter 6 Chapter 7 Chapter 8 Chapter 9 Chapter 10 Chapter 11 Part Two Chapter 12 Chapter 13 Chapter 14 Chapter 15 Chapter 16 Chapter 17 Chapter 18. Chapter 19 Chapter 20 Chapter 21 Chapter 22 Chapter 23 Chapter 24 Chapter 25 Chapter 26

DEDICATION PART ONE Chapter 1 Chapter 2 Chapter 3 Chapter 4 Chapter 5 Chapter 6 Chapter 7 Chapter 8 Chapter 9 Chapter 10 Chapter 11 PART TWO Chapter 12 Chapter 13 Chapter 14 Chapter 15 Chapter 16 Chapter 17 Chapter 18 Chapter 19 Chapter 20 Chapter 21 Chapter 22 Chapter 23 .

o To handle the exception o Or declare the exception may be thrown Throw early, catch late Throw an exception as soon as a problem is detected. Catch it only when the problem can be handled Just as trucks with large or hazardous loads carry warning signs, the throws clause warns the caller that an exception may occur.

architecture, see the Programming Model chapter of the Nios II Processor Reference Handbook. Nios II Exceptions Overview Nios II exception handling is implemented in classic RISC fashion, i.e., all exception types are handled by a single exception handler. As such, all exceptions

About the husband’s secret. Dedication Epigraph Pandora Monday Chapter One Chapter Two Chapter Three Chapter Four Chapter Five Tuesday Chapter Six Chapter Seven. Chapter Eight Chapter Nine Chapter Ten Chapter Eleven Chapter Twelve Chapter Thirteen Chapter Fourteen Chapter Fifteen Chapter Sixteen Chapter Seventeen Chapter Eighteen

18.4 35 18.5 35 I Solutions to Applying the Concepts Questions II Answers to End-of-chapter Conceptual Questions Chapter 1 37 Chapter 2 38 Chapter 3 39 Chapter 4 40 Chapter 5 43 Chapter 6 45 Chapter 7 46 Chapter 8 47 Chapter 9 50 Chapter 10 52 Chapter 11 55 Chapter 12 56 Chapter 13 57 Chapter 14 61 Chapter 15 62 Chapter 16 63 Chapter 17 65 .