Đang chuẩn bị liên kết để tải về tài liệu:
Java C5. Exception Handling

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

Exceptional event Error that occurs during runtime Cause normal program flow to be disrupted Examples Divide by zero errors Accessing the elements of an array beyond its range Invalid input Hard disk crash Opening a nonexistent file Heap memory exhausted | Chapter 5. Exception Handling ITSS Java Programming CAO Tuan-Dung, HUT What is an exception? Exceptional event Error that occurs during runtime Cause normal program flow to be disrupted Examples Divide by zero errors Accessing the elements of an array beyond its range Invalid input Hard disk crash Opening a non-existent file Heap memory exhausted Example // divide by zero class DivByZero { public static void main(String args[]) { System.out.println(3/0); System.out.println(“Pls. print me.”); } } // array out of bound int array[] = new int[2]; array[0] = 1; array[1] = 2; array[2] = 3; // execute method of object that does not exist String s = null; s.length(); Exception Object ArithmeticException Exception Object ArrayIndexOutOfBoundException Exception Object NullPointerException Default exception handling Displays this error message Exception in thread "main" java.lang.ArithmeticException: / by zero at DivByZero.main(DivByZero.java:3) Default exception handler Provided | Chapter 5. Exception Handling ITSS Java Programming CAO Tuan-Dung, HUT What is an exception? Exceptional event Error that occurs during runtime Cause normal program flow to be disrupted Examples Divide by zero errors Accessing the elements of an array beyond its range Invalid input Hard disk crash Opening a non-existent file Heap memory exhausted Example // divide by zero class DivByZero { public static void main(String args[]) { System.out.println(3/0); System.out.println(“Pls. print me.”); } } // array out of bound int array[] = new int[2]; array[0] = 1; array[1] = 2; array[2] = 3; // execute method of object that does not exist String s = null; s.length(); Exception Object ArithmeticException Exception Object ArrayIndexOutOfBoundException Exception Object NullPointerException Default exception handling Displays this error message Exception in thread "main" java.lang.ArithmeticException: / by zero at DivByZero.main(DivByZero.java:3) Default exception handler Provided by Java runtime Prints out exception description Prints the stack trace Hierarchy of methods where the exception occurred Causes the program to terminate What Happens When an Exception Occurs? When an exception occurs within a method, the method creates an exception object and hands it off to the runtime system Creating an exception object and handing it to the runtime system is called “throwing an exception” Exception object contains information about the error, including its type and the state of the program when the error occurred Lab: Exception Run this program and observe the exceptions exceptions of the type that is different according to the specified value. prompt> java Exceptions ExceptionNO:1→ArrayIndexOutOfBoundsException ExceptionNO:2→NullPointerException ExceptionNO:3→ArithmeticException Exception.java class Exceptions { public static void main(String args[])throws Exception { if(args.length != 1) { System.out.println("Usage : java Exceptions .

TÀI LIỆU 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.