tailieunhanh - Lecture Java™ How to Program (8/e) - Chapter 11: Exception handling
After completing this unit, you should be able to: How exception and error handling works; to use try, throw and catch to detect, indicate and handle exceptions, respectively; to use the finally block to release resources; how stack unwinding enables exceptions not caught in one scope to be caught in another scope; how stack traces help in debugging;. | Java™ How to Program, 8/e (C) 2010 Pearson Education, Inc. All rights reserved. (C) 2010 Pearson Education, Inc. All rights reserved. (C) 2010 Pearson Education, Inc. All rights reserved. Exception handling Exception—an indication of a problem that occurs during a program’s execution. The name “exception” implies that the problem occurs infrequently. With exception handling, a program can continue executing (rather than terminating) after dealing with a problem. Mission-critical or business-critical computing. Robust and fault-tolerant programs (., programs that can deal with problems as they arise and continue executing). (C) 2010 Pearson Education, Inc. All rights reserved. (C) 2010 Pearson Education, Inc. All rights reserved. ArrayIndexOutOfBoundsException occurs when an attempt is made to access an element past either end of an array. ClassCastException occurs when an attempt is made to cast an object that does not have an is-a relationship with the type . | Java™ How to Program, 8/e (C) 2010 Pearson Education, Inc. All rights reserved. (C) 2010 Pearson Education, Inc. All rights reserved. (C) 2010 Pearson Education, Inc. All rights reserved. Exception handling Exception—an indication of a problem that occurs during a program’s execution. The name “exception” implies that the problem occurs infrequently. With exception handling, a program can continue executing (rather than terminating) after dealing with a problem. Mission-critical or business-critical computing. Robust and fault-tolerant programs (., programs that can deal with problems as they arise and continue executing). (C) 2010 Pearson Education, Inc. All rights reserved. (C) 2010 Pearson Education, Inc. All rights reserved. ArrayIndexOutOfBoundsException occurs when an attempt is made to access an element past either end of an array. ClassCastException occurs when an attempt is made to cast an object that does not have an is-a relationship with the type specified in the cast operator. A NullPointerException occurs when a null reference is used where an object is expected. Only classes that extend Throwable (package ) directly or indirectly can be used with exception handling. (C) 2010 Pearson Education, Inc. All rights reserved. Programs frequently test conditions to determine how program execution should proceed. Consider the following pseudocode: Perform a task If the preceding task did not execute correctly Perform error processing Perform next task If the preceding task did not execute correctly Perform error processing Begins by performing a task; then tests whether it executed correctly. If not, perform error processing. Otherwise, continue with the next task. Intermixing program and error-handling logic in this manner can make programs difficult to read, modify, maintain and debug—especially in large applications. (C) 2010 Pearson Education, Inc. All rights reserved. (C) 2010 Pearson Education, Inc. All rights .
đang nạp các trang xem trước