Đang chuẩn bị liên kết để tải về tài liệu:
Lecture An introduction to object-oriented programming with Java: Chapter 8 - C. Thomas Wu

Đang chuẩn bị nút TẢI XUỐNG, xin hãy chờ

Program correctness guarantees correct results for all valid input. But what happens when the input is invalid? Another important criterion of program reliability is the robustness, which measures how well the program runs under various conditions. In this chapter, we will describe how to code this exception-handling mechanism in Java to improve the program’s robustness. | ©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter 8- Chapter 8 Exceptions and Assertions Animated Version Introduction to OOP with Java 4th Ed, C. Thomas Wu © The McGraw-Hill Companies, Inc. Objectives After you have read and studied this chapter, you should be able to Improve the reliability of code by incorporating exception-handling and assertion mechanisms. Write methods that propagate exceptions. Implement the try-catch blocks for catching and handling exceptions. Write programmer-defined exception classes. Distinguish the checked and unchecked, or runtime, exceptions. Intro to OOP with Java, C. Thomas Wu ©The McGraw-Hill Companies, Inc. ©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter 8 - Definition An exception represents an error condition that can occur during the normal course of program execution. When an exception occurs, or is thrown, the normal sequence of flow is terminated. The exception-handling routine is then executed; we say the thrown exception is caught. Intro to OOP with Java, C. Thomas Wu ©The McGraw-Hill Companies, Inc. We can increase our programs’ reliability and robustness if we catch the exceptions ourselves using error recovery routines we develop. One way to do this is to wrap the statements that may throw an exception with the try-catch control statement. ©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter 8 - Not Catching Exceptions Scanner scanner = new Scanner(System.in); System.out.println(“Enter integer:"); int number = scanner.nextInt(); Exception in thread “main” java.lang.InputMismatchException at java.util.Scanner.throwFor(Scanner.java:819) at java.util.Scanner.next(Scanner.java:1431) at java.util.Scanner.nextInt(Scanner.java:2040) at java.util.Scanner.nextInt(Scanner.java:2000) at Ch8Sample1.main(Ch8Sample1.java:35) Error message for invalid input Intro to OOP with Java, C. Thomas Wu | ©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter 8- Chapter 8 Exceptions and Assertions Animated Version Introduction to OOP with Java 4th Ed, C. Thomas Wu © The McGraw-Hill Companies, Inc. Objectives After you have read and studied this chapter, you should be able to Improve the reliability of code by incorporating exception-handling and assertion mechanisms. Write methods that propagate exceptions. Implement the try-catch blocks for catching and handling exceptions. Write programmer-defined exception classes. Distinguish the checked and unchecked, or runtime, exceptions. Intro to OOP with Java, C. Thomas Wu ©The McGraw-Hill Companies, Inc. ©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter 8 - Definition An exception represents an error condition that can occur during the normal course of program execution. When an exception occurs, or is thrown, the normal sequence of flow is terminated.

TAILIEUCHUNG - Chia sẻ tài liệu không giới hạn
Địa chỉ : 444 Hoang Hoa Tham, Hanoi, Viet Nam
Website : tailieuchung.com
Email : tailieuchung20@gmail.com
Tailieuchung.com là thư viện tài liệu trực tuyến, nơi chia sẽ trao đổi hàng triệu tài liệu như luận văn đồ án, sách, giáo trình, đề thi.
Chúng tôi không chịu trách nhiệm liên quan đến các vấn đề bản quyền nội dung tài liệu được thành viên tự nguyện đăng tải lên, nếu phát hiện thấy tài liệu xấu hoặc tài liệu có bản quyền xin hãy email cho chúng tôi.
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.