You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 9406cca
Browse filesBrowse the repository at this point in the historyBrowse files
Copy file name to clipboardExpand all lines: exercises/error-handling/README.md
+38Lines changed: 38 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -9,6 +9,44 @@ This exercise requires you to handle various errors. Because error handling
9
9
is rather programming language specific you'll have to refer to the tests
10
10
for your track to see what's exactly required.
11
11
12
+
# Java Tips
13
+
14
+
This exercise requires you to handle exceptions. An [exception](https://docs.oracle.com/javase/tutorial/essential/exceptions/definition.html) is an event, which occurs during the execution of a program, that disrupts the normal flow of the program's instructions.
15
+
16
+
In Java, there are two types of exceptions: checked and unchecked exceptions.
17
+
18
+
-[Checked vs Unchecked Exceptions in Java](https://www.geeksforgeeks.org/checked-vs-unchecked-exceptions-in-java/)
19
+
20
+
-[Unchecked Exceptions — The Controversy](https://docs.oracle.com/javase/tutorial/essential/exceptions/runtime.html)
21
+
22
+
## Checked exceptions
23
+
24
+
Checked exceptions are the exceptions that are checked at [compile time](https://en.wikipedia.org/wiki/Compile_time).
25
+
26
+
### Practical implications
27
+
28
+
You have to declare them in the [method signature](https://docs.oracle.com/javase/tutorial/java/javaOO/methods.html) of any method that can [throw](https://docs.oracle.com/javase/tutorial/essential/exceptions/throwing.html) a checked exception and handle or rethrow them when calling any method that can throw a checked exception.
29
+
30
+
This is because checked exceptions are meant to be handled at runtime, i.e. they are errors you can recover from.
31
+
32
+
### Examples of where they are used
33
+
34
+
They're often used when a method can't return any valid result, for example a search method which hasn't found the item it was searching for.
35
+
36
+
It's an alternative to returning null or a error code. A checked exception is better than those alternatives because it forces the user of the method to consider the error case.
37
+
38
+
## Unchecked exceptions
39
+
40
+
Unchecked exceptions are the exceptions that are not checked at [compile time](https://en.wikipedia.org/wiki/Compile_time).
41
+
42
+
### Practical implications
43
+
44
+
You don't have to declare them in the [method signature](https://docs.oracle.com/javase/tutorial/java/javaOO/methods.html) of methods that can [throw](https://docs.oracle.com/javase/tutorial/essential/exceptions/throwing.html) an unchecked exception and handle or rethrow them when calling any method that can throw an unchecked exception.
45
+
46
+
### Examples of where they are used
47
+
48
+
Unchecked exceptions are mean to be used for any error than can't be handled at runtime, e.g. running out of memory.
49
+
12
50
# Running the tests
13
51
14
52
You can run all the tests for an exercise by entering
0 commit comments