Main content:
  How to validate input data (Chapter 5)
      How to handle exceptions
      How to validate data
      The Future Value application with data validation
  How to test and debug an application (Chapter 6)

      Basic skills for testing and debugging
      How to use Eclipse to debug an application

            ------------
How to validate input data (Chapter 5)
1. How to handle exceptions
- Cú pháp:

- Danh sách các lớp ngoại lệ:
RuntimeException
Lớp  sở cho nhiều ngoại lệ java.lang
ArthmeticException 
Lỗi về số học,  dụ như ‘chia cho 0’.
IllegalAccessException 
Lớp không thể truy cập.
IllegalArgumentException
Đối số không hợp lệ
ArrayIndexOutOfBoundsExeption 
Lỗi tràn mảng
NullPointerException 
Khi truy cập đối tượng null
SecurityException 
 chế bảo mật không cho phép thực hiện
ClassNotFoundException 
Không thể nạp lớp yêu cầu
NumberFormatException 
Việc chuyển đối từ chuỗi sang số thực không thành công
AWTException 
Ngoại lệ về AWT
IOException 
Lớp cha của các lớp ngoại lệ I/O
FileNotFoundException 
Không thể định vị tập tin
EOFException 
Kết thúc một tập tin.
NoSuchMethodException 
Phương thức yêu cầu không tồn tại
InterruptedException 
Khi một luồng bị ngắt

Ví dụ 1: Lỗi chia cho 0
import java.util.Scanner;

public class Main {
       public static void main(String[] args) {
              float x = 0;
              Scanner input = new Scanner(System.in);
             
              System.out.println("y=");
              int y = input.nextInt();
              try {
                     x = 10 / y;  
              } catch (ArithmeticException e) {
                     System.out.print("Error: ");
                     e.printStackTrace();
              }
              System.out.println("x = " + x);
       }
}


Ví dụ 2: Lỗi truy cập ngoài mảng
public class DemoException {
       public static void main(String[] args) {
              int m[] = new int[10];
              try
              {
                     for (int i = 0; i <= 10; i++)
                     {
                           m[i] = i * i;
                     }
              }
              catch(ArrayIndexOutOfBoundsException e)
              {
                     System.out.print("Error: Tạo mảng lỗi. ");
                     e.printStackTrace();
              }
       }
}

2. How to validate data


3. The Future Value application with data validation


How to test and debug an application (Chapter 6)
4. Basic skills for testing and debugging

5. How to use Eclipse to debug an application