TAILIEUCHUNG - Software Engineering For Students: A Programming Approach Part 28

Software Engineering For Students: A Programming Approach Part 28. This fully revised version of Doug Bell's Software Engineering: A Programming Approach continues to use the successful formula of the previous editions. The author's approach is to present the main principles, techniques and tools used in software engineering, one by one, chapter by chapter. This book is a unique introduction to software engineering for all students of computer science and its related disciplines. It is also ideal for practitioners wishing to remain current with new developments in the area | 248 Chapter 17 Software robustness Let us turn to examining how an exception is thrown using the same example. In Java the method parseint can be written as follows -----------------------------------------------------------------------------1 public int parseInt String string throws NumberFormatException int number 0 for int i 0 i i char c i if c 0 c 9 throw new NumberFormatException number number 10 c - 0 return number ------------------------------------------------------------------------------ You can see that in the heading of the method the exception that may be thrown is declared along with the specification of any parameters and return value. If this method detects that any of the characters within the string are illegal it executes a throw instruction. This immediately terminates the method and transfers control to a catch block designed to handle the exception. In our example the catch block is within the method that calls parseint. Alternatively the try-catch combination can be written within the same method as the throw statement. Or it can be written within any of the methods in the calling chain that led to calling parseint. Thus the designer can choose an appropriate place in the software structure at which to carry exception handling. The position in which the exception handler is written helps both to determine the action to be taken and what happens after it has dealt with the situation. SELF-TEST QUESTION The method parseint does not throw an exception if the string is of zero length. Amend it so that it throws the same exception in this situation. What happens after an exception has been handled In the above example the catch block ends with a return statement which exits from the current method actionPerformed and returns control to its caller. This is the appropriate action in this case - the program is able to recover and continue in a useful way. In general the options are either to recover from the .

TỪ KHÓA LIÊN QUAN
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.