-
-
Notifications
You must be signed in to change notification settings - Fork 739
Update exception terminology to clarify types of exceptions #2954
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
746fae7
498b1e4
d3e76c6
88297ef
f27f57c
debab47
5346c08
b1ddf8a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -8,11 +8,10 @@ An exception is an event that occurs during the execution of a program that disr | |||||||||||
| Exceptions are raised explicitly in Java, and the act of raising an exception is called _throwing an exception_. | ||||||||||||
| The act of handling an exception is called _catching an exception_. | ||||||||||||
|
|
||||||||||||
| Java distinguishes three types of exceptions: | ||||||||||||
| Java distinguishes two types of exceptions: | ||||||||||||
|
|
||||||||||||
| 1. Checked exceptions | ||||||||||||
| 2. Unchecked exceptions | ||||||||||||
| 3. Errors | ||||||||||||
|
|
||||||||||||
| ### Checked exceptions | ||||||||||||
|
|
||||||||||||
|
|
@@ -21,7 +20,7 @@ An example of a checked exception is the `FileNotFoundException` which occurs wh | |||||||||||
|
|
||||||||||||
| 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. | ||||||||||||
|
|
||||||||||||
| All exceptions in Java that do not inherit from `RuntimeException` or `Error` are considered checked exceptions. | ||||||||||||
| All exceptions in Java that do not inherit from `RuntimeException` are checked exceptions. | ||||||||||||
|
|
||||||||||||
| ### Unchecked exceptions | ||||||||||||
|
|
||||||||||||
|
|
@@ -30,17 +29,17 @@ An example of an unchecked exception is the `NullPointerException` which occurs | |||||||||||
|
|
||||||||||||
| 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. | ||||||||||||
|
|
||||||||||||
| All exceptions in Java that inherit from `RuntimeException` are considered unchecked exceptions. | ||||||||||||
| All exceptions in Java that inherit from `RuntimeException` are unchecked exceptions. | ||||||||||||
|
|
||||||||||||
| ### Errors | ||||||||||||
| ## Errors | ||||||||||||
|
||||||||||||
|
|
||||||||||||
| _Errors_ are exceptional conditions that are external to an application. | ||||||||||||
| Java also has a separate category called _Errors_ which are serious problems that are external to an application. | ||||||||||||
| 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. | ||||||||||||
|
|
||||||||||||
| Like unchecked exceptions, errors are not checked at compile-time. | ||||||||||||
| They are not usually thrown from application code. | ||||||||||||
| Like unchecked exceptions, errors are not checked at compile-time and are not usually thrown from application code. | ||||||||||||
| Unlike exceptions, Errors represent serious system-level problems that applications should generally not attempt to catch or handle. | ||||||||||||
|
||||||||||||
| Like unchecked exceptions, errors are not checked at compile-time and are not usually thrown from application code. | |
| Unlike exceptions, Errors represent serious system-level problems that applications should generally not attempt to catch or handle. | |
| Like unchecked exceptions, errors are not checked at compile-time. | |
| The difference is that they represent system level problems and are generally thrown by the Java Virtual machine or environment instead of the application. | |
| Applications should generally not attempt to catch or handle them. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if we should mention the
Exceptionclass somewhere sinceRuntimeExceptionextendsException.