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
Copy file name to clipboardExpand all lines: concepts/exceptions/about.md
+16-14Lines changed: 16 additions & 14 deletions
Original file line number
Diff line number
Diff line change
@@ -8,11 +8,12 @@ An exception is an event that occurs during the execution of a program that disr
8
8
Exceptions are raised explicitly in Java, and the act of raising an exception is called _throwing an exception_.
9
9
The act of handling an exception is called _catching an exception_.
10
10
11
-
Java distinguishes three types of exceptions:
11
+
In Java, all exceptions are subclasses of the `Exception` class, which itself is a subclass of `Throwable`.
12
+
13
+
Java distinguishes two types of exceptions:
12
14
13
15
1. Checked exceptions
14
16
2. Unchecked exceptions
15
-
3. Errors
16
17
17
18
### Checked exceptions
18
19
@@ -21,7 +22,7 @@ An example of a checked exception is the `FileNotFoundException` which occurs wh
21
22
22
23
This type of exception is checked at compile-time: methods that throw checked exceptions should specify this in their method signature, and code calling a method that might throw a checked exception is required to handle it or the code will not compile.
23
24
24
-
All exceptions in Java that do not inherit from `RuntimeException` or `Error` are considered checked exceptions.
25
+
All checked exceptions are subclasses of `Exception`that do not extend `RuntimeException`.
25
26
26
27
### Unchecked exceptions
27
28
@@ -30,17 +31,7 @@ An example of an unchecked exception is the `NullPointerException` which occurs
30
31
31
32
This type of exception is not checked at compile-time: methods that throw unchecked exceptions are not required to specify this in their method signature, and code calling a method that might throw an unchecked exception is not required to handle it.
32
33
33
-
All exceptions in Java that inherit from `RuntimeException` are considered unchecked exceptions.
34
-
35
-
### Errors
36
-
37
-
_Errors_ are exceptional conditions that are external to an application.
38
-
An example of an error is the `OutOfMemoryError` which occurs when an application is trying to use more memory than is available on the system.
39
-
40
-
Like unchecked exceptions, errors are not checked at compile-time.
41
-
They are not usually thrown from application code.
42
-
43
-
All exceptions in Java that inherit from `Error` are considered errors.
34
+
All unchecked exceptions inherit from `RuntimeException`, which itself is an extension of `Exception`.
Java also has a separate category called _Errors_ which are serious problems that are external to an application.
132
+
An example of an error is the `OutOfMemoryError` which occurs when an application is trying to use more memory than is available on the system.
133
+
134
+
Like unchecked exceptions, errors are not checked at compile-time.
135
+
The difference is that they represent system level problems and are generally thrown by the Java Virtual machine or environment instead of the application.
136
+
Applications should generally not attempt to catch or handle them.
137
+
138
+
All errors in Java inherit from the `Error` class.
139
+
138
140
## When not to use exceptions
139
141
140
142
As stated previously, exceptions are events that disrupt the normal flow of instructions, and are used to handle _exceptional events_.
Copy file name to clipboardExpand all lines: concepts/exceptions/introduction.md
+16-14Lines changed: 16 additions & 14 deletions
Original file line number
Diff line number
Diff line change
@@ -8,11 +8,12 @@ An exception is an event that occurs during the execution of a program that disr
8
8
Exceptions are raised explicitly in Java, and the act of raising an exception is called _throwing an exception_.
9
9
The act of handling an exception is called _catching an exception_.
10
10
11
-
Java distinguishes three types of exceptions:
11
+
In Java, all exceptions are subclasses of the `Exception` class, which itself is a subclass of `Throwable`.
12
+
13
+
Java distinguishes two types of exceptions:
12
14
13
15
1. Checked exceptions
14
16
2. Unchecked exceptions
15
-
3. Errors
16
17
17
18
### Checked exceptions
18
19
@@ -21,7 +22,7 @@ An example of a checked exception is the `FileNotFoundException` which occurs wh
21
22
22
23
This type of exception is checked at compile-time: methods that throw checked exceptions should specify this in their method signature, and code calling a method that might throw a checked exception is required to handle it or the code will not compile.
23
24
24
-
All exceptions in Java that do not inherit from `RuntimeException` or `Error` are considered checked exceptions.
25
+
All checked exceptions are subclasses of `Exception`that do not extend `RuntimeException`.
25
26
26
27
### Unchecked exceptions
27
28
@@ -30,17 +31,7 @@ An example of an unchecked exception is the `NullPointerException` which occurs
30
31
31
32
This type of exception is not checked at compile-time: methods that throw unchecked exceptions are not required to specify this in their method signature, and code calling a method that might throw an unchecked exception is not required to handle it.
32
33
33
-
All exceptions in Java that inherit from `RuntimeException` are considered unchecked exceptions.
34
-
35
-
### Errors
36
-
37
-
_Errors_ are exceptional conditions that are external to an application.
38
-
An example of an error is the `OutOfMemoryError` which occurs when an application is trying to use more memory than is available on the system.
39
-
40
-
Like unchecked exceptions, errors are not checked at compile-time.
41
-
They are not usually thrown from application code.
42
-
43
-
All exceptions in Java that inherit from `Error` are considered errors.
34
+
All unchecked exceptions inherit from `RuntimeException`, which itself is an extension of `Exception`.
44
35
45
36
## Throwing exceptions
46
37
@@ -134,3 +125,14 @@ Withdrawing -10.0
134
125
Withdrawal failed: Cannot withdraw a negative amount
135
126
Current balance: 5.0
136
127
```
128
+
129
+
## Errors
130
+
131
+
Java also has a separate category called _Errors_ which are serious problems that are external to an application.
132
+
An example of an error is the `OutOfMemoryError` which occurs when an application is trying to use more memory than is available on the system.
133
+
134
+
Like unchecked exceptions, errors are not checked at compile-time.
135
+
The difference is that they represent system level problems and are generally thrown by the Java Virtual machine or environment instead of the application.
136
+
Applications should generally not attempt to catch or handle them.
137
+
138
+
All errors in Java inherit from the `Error` class.
Copy file name to clipboardExpand all lines: exercises/concept/calculator-conundrum/.docs/introduction.md
+16-14Lines changed: 16 additions & 14 deletions
Original file line number
Diff line number
Diff line change
@@ -10,11 +10,12 @@ An exception is an event that occurs during the execution of a program that disr
10
10
Exceptions are raised explicitly in Java, and the act of raising an exception is called _throwing an exception_.
11
11
The act of handling an exception is called _catching an exception_.
12
12
13
-
Java distinguishes three types of exceptions:
13
+
In Java, all exceptions are subclasses of the `Exception` class, which itself is a subclass of `Throwable`.
14
+
15
+
Java distinguishes two types of exceptions:
14
16
15
17
1. Checked exceptions
16
18
2. Unchecked exceptions
17
-
3. Errors
18
19
19
20
#### Checked exceptions
20
21
@@ -23,7 +24,7 @@ An example of a checked exception is the `FileNotFoundException` which occurs wh
23
24
24
25
This type of exception is checked at compile-time: methods that throw checked exceptions should specify this in their method signature, and code calling a method that might throw a checked exception is required to handle it or the code will not compile.
25
26
26
-
All exceptions in Java that do not inherit from `RuntimeException` or `Error` are considered checked exceptions.
27
+
All checked exceptions are subclasses of `Exception`that do not extend `RuntimeException`.
27
28
28
29
#### Unchecked exceptions
29
30
@@ -32,17 +33,7 @@ An example of an unchecked exception is the `NullPointerException` which occurs
32
33
33
34
This type of exception is not checked at compile-time: methods that throw unchecked exceptions are not required to specify this in their method signature, and code calling a method that might throw an unchecked exception is not required to handle it.
34
35
35
-
All exceptions in Java that inherit from `RuntimeException` are considered unchecked exceptions.
36
-
37
-
#### Errors
38
-
39
-
_Errors_ are exceptional conditions that are external to an application.
40
-
An example of an error is the `OutOfMemoryError` which occurs when an application is trying to use more memory than is available on the system.
41
-
42
-
Like unchecked exceptions, errors are not checked at compile-time.
43
-
They are not usually thrown from application code.
44
-
45
-
All exceptions in Java that inherit from `Error` are considered errors.
36
+
All unchecked exceptions inherit from `RuntimeException`, which itself is an extension of `Exception`.
46
37
47
38
### Throwing exceptions
48
39
@@ -136,3 +127,14 @@ Withdrawing -10.0
136
127
Withdrawal failed: Cannot withdraw a negative amount
137
128
Current balance: 5.0
138
129
```
130
+
131
+
### Errors
132
+
133
+
Java also has a separate category called _Errors_ which are serious problems that are external to an application.
134
+
An example of an error is the `OutOfMemoryError` which occurs when an application is trying to use more memory than is available on the system.
135
+
136
+
Like unchecked exceptions, errors are not checked at compile-time.
137
+
The difference is that they represent system level problems and are generally thrown by the Java Virtual machine or environment instead of the application.
138
+
Applications should generally not attempt to catch or handle them.
139
+
140
+
All errors in Java inherit from the `Error` class.
0 commit comments