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
+15-12Lines changed: 15 additions & 12 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -8,6 +8,8 @@ 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
+
In Java, all exceptions are subclasses of the `Exception` class, which itself is a subclass of `Throwable`.
12
+
11
13
Java distinguishes two types of exceptions:
12
14
13
15
1. Checked exceptions
@@ -20,7 +22,7 @@ An example of a checked exception is the `FileNotFoundException` which occurs wh
20
22
21
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.
22
24
23
-
All exceptions in Java that do not inherit from `RuntimeException` are checked exceptions.
25
+
All checked exceptions are subclasses of `Exception`that do not extend `RuntimeException`.
24
26
25
27
### Unchecked exceptions
26
28
@@ -29,17 +31,7 @@ An example of an unchecked exception is the `NullPointerException` which occurs
29
31
30
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.
31
33
32
-
All exceptions in Java that inherit from `RuntimeException` are unchecked exceptions.
33
-
34
-
## Errors
35
-
36
-
Java also has a separate category called _Errors_ which are serious problems that are external to an application.
37
-
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.
38
-
39
-
Like unchecked exceptions, errors are not checked at compile-time and are not usually thrown from application code.
40
-
Unlike exceptions, Errors represent serious system-level problems that applications should generally not attempt to catch or handle.
41
-
42
-
All errors in Java inherit from the `Error` class.
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
+
137
140
## When not to use exceptions
138
141
139
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: exercises/concept/calculator-conundrum/.docs/introduction.md
+15-12Lines changed: 15 additions & 12 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -10,6 +10,8 @@ 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
+
In Java, all exceptions are subclasses of the `Exception` class, which itself is a subclass of `Throwable`.
14
+
13
15
Java distinguishes two types of exceptions:
14
16
15
17
1. Checked exceptions
@@ -22,7 +24,7 @@ An example of a checked exception is the `FileNotFoundException` which occurs wh
22
24
23
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.
24
26
25
-
All exceptions in Java that do not inherit from `RuntimeException` are checked exceptions.
27
+
All checked exceptions are subclasses of `Exception`that do not extend `RuntimeException`.
26
28
27
29
#### Unchecked exceptions
28
30
@@ -31,17 +33,7 @@ An example of an unchecked exception is the `NullPointerException` which occurs
31
33
32
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.
33
35
34
-
All exceptions in Java that inherit from `RuntimeException` are unchecked exceptions.
35
-
36
-
### Errors
37
-
38
-
Java also has a separate category called _Errors_ which are serious problems that are external to an application.
39
-
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.
40
-
41
-
Like unchecked exceptions, errors are not checked at compile-time and are not usually thrown from application code.
42
-
Unlike exceptions, Errors represent serious system-level problems that applications should generally not attempt to catch or handle.
43
-
44
-
All errors in Java inherit from the `Error` class.
36
+
All unchecked exceptions inherit from `RuntimeException`, which itself is an extension of `Exception`.
45
37
46
38
### Throwing exceptions
47
39
@@ -135,3 +127,14 @@ Withdrawing -10.0
135
127
Withdrawal failed: Cannot withdraw a negative amount
136
128
Current balance: 5.0
137
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