"Xin chào, Amigo. Đây là một số nhiệm vụ thú vị liên quan đến việc bắt ngoại lệ."
"Đây là một mẹo: hãy viết chương trình của bạn, xem loại ngoại lệ nào xảy ra và sau đó thay đổi mã để xử lý chúng."
3
Nhiệm vụ
Java Syntax, mức độ, bài học
Exception when working with numbers
Esteemed colleagues, things are getting serious. We're starting sting operation to catch exceptions. The secret CodeGym center has sent the following task, and I quote: "Catch (and display the type of) the exception that occurs when the following code is executed: int a = 42 / 0;". Note: Complete this task immediately.
3
Nhiệm vụ
Java Syntax, mức độ, bài học
Exception while working with strings
In Java, an exception is an object. And it has a type, of course. This all seems vague until you start working with them. Practice will dispel the uncertainty. Be more confident in catching exceptions: catch and display the exception (indicating its type) that occurs when executing the following code: String s = null; String m = s.toLowerCase().
3
Nhiệm vụ
Java Syntax, mức độ, bài học
Exception when working with arrays
We're mastering the mechanism for handling errors in the program. By that I mean exceptions. This time, your task is to catch exceptions when working with arrays. An application has the following lines of code: int[] m = new int[2]; m[8] = 5; Catch the exception that occurs when this code is executed, and then display it on the screen and indicate its type.
3
Nhiệm vụ
Java Syntax, mức độ, bài học
Exception when working with List collections
By the ninth level, we've already got some idea of List collections, and exceptions. Let's bring this knowledge together: catch exceptions when executing the following code: ArrayList<String> list = new ArrayList<String>(); String s = list.get(18); Catch and display the exception on the screen, indicating its type.
3
Nhiệm vụ
Java Syntax, mức độ, bài học
Exception when working with Map collections
We have some questionable code. It's time to deploy an agent to intercept (catch) exceptions. Here's the code: HashMap<String, String> map = new HashMap<String, String>(null); map.put(null, null); map.remove(null); Agent, your task, as usual, is to catch the exception and display it on the screen. Don't forget to only display the exception type.
3
Nhiệm vụ
Java Syntax, mức độ, bài học
Exception when working with numbers
Another task about catching exceptions arrived today at the secret CodeGym center. This time, we have to catch an exception and immediately display it on the screen. Don't forget to indicate its type. The exception in question will occur when the following code is executed: int num = Integer.parseInt("XYZ"); System.out.println(num).