TAILIEUCHUNG - Lecture An introduction to Object-Oriented Programming with Java - Chapter 8: Exceptions and assertions

After you have read and studied this chapter, you should be able to: Improve the reliability of code by incorporating exception-handling and assertion routines, write methods that propagate exceptions, implement catch-try blocks for catching and handling thrown exceptions,. | Chapter 8 Exceptions and Assertions Chapter 8 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 routines. Write methods that propagate exceptions. Implement catch-try blocks for catching and handling thrown exceptions. ©TheMcGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter 8 Objectives After you have read and studied this chapter, you should be able to Write programmer-defined exception classes. Distinguish between checked and unchecked, or runtime, exceptions. Use assertions in methods to increase the chance of detecting bugs during development. Construct a program using the supervisor-subordinate design pattern. ©TheMcGraw-Hill Companies, Inc. Permission required for reproduction or display. Catching Exceptions 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. ©TheMcGraw-Hill Companies, Inc. Permission required for reproduction or display. Catching Exceptions 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. ©TheMcGraw-Hill Companies, Inc. Permission required for reproduction or display. Catching Exceptions inputStr = (null, prompt); try { age = (inputStr); } catch (NumberFormatException e){ (null, “’” + inputStr + ‘ is invalid\n” + “Please enter digits only”); ©TheMcGraw-Hill Companies, Inc. Permission required for reproduction or display. Catching Exceptions Statements in the try block are executed in sequence. When .

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.