Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion concepts/exceptions/.meta/config.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"blurb": "Exceptions are thrown when an error that needs special handling occurs.",
"authors": ["sanderploegsma"],
"contributors": []
"contributors": ["BahaaMohamed98"]
}
30 changes: 16 additions & 14 deletions concepts/exceptions/about.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@ 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:
In Java, all exceptions are subclasses of the `Exception` class, which itself is a subclass of `Throwable`.

Java distinguishes two types of exceptions:

1. Checked exceptions
2. Unchecked exceptions
3. Errors

### Checked exceptions

Expand All @@ -21,7 +22,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 checked exceptions are subclasses of `Exception` that do not extend `RuntimeException`.

### Unchecked exceptions

Expand All @@ -30,17 +31,7 @@ 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.

### Errors

_Errors_ are exceptional conditions 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.

All exceptions in Java that inherit from `Error` are considered errors.
All unchecked exceptions inherit from `RuntimeException`, which itself is an extension of `Exception`.

## Throwing exceptions

Expand Down Expand Up @@ -135,6 +126,17 @@ Withdrawal failed: Cannot withdraw a negative amount
Current balance: 5.0
```

## Errors

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.
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.

All errors in Java inherit from the `Error` class.

## When not to use exceptions

As stated previously, exceptions are events that disrupt the normal flow of instructions, and are used to handle _exceptional events_.
Expand Down
30 changes: 16 additions & 14 deletions concepts/exceptions/introduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@ 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:
In Java, all exceptions are subclasses of the `Exception` class, which itself is a subclass of `Throwable`.

Java distinguishes two types of exceptions:

1. Checked exceptions
2. Unchecked exceptions
3. Errors

### Checked exceptions

Expand All @@ -21,7 +22,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 checked exceptions are subclasses of `Exception` that do not extend `RuntimeException`.

### Unchecked exceptions

Expand All @@ -30,17 +31,7 @@ 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.

### Errors

_Errors_ are exceptional conditions 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.

All exceptions in Java that inherit from `Error` are considered errors.
All unchecked exceptions inherit from `RuntimeException`, which itself is an extension of `Exception`.

## Throwing exceptions

Expand Down Expand Up @@ -134,3 +125,14 @@ Withdrawing -10.0
Withdrawal failed: Cannot withdraw a negative amount
Current balance: 5.0
```

## Errors

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.
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.

All errors in Java inherit from the `Error` class.
30 changes: 16 additions & 14 deletions exercises/concept/calculator-conundrum/.docs/introduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@ 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:
In Java, all exceptions are subclasses of the `Exception` class, which itself is a subclass of `Throwable`.

Java distinguishes two types of exceptions:

1. Checked exceptions
2. Unchecked exceptions
3. Errors

#### Checked exceptions

Expand All @@ -23,7 +24,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 checked exceptions are subclasses of `Exception` that do not extend `RuntimeException`.

#### Unchecked exceptions

Expand All @@ -32,17 +33,7 @@ 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.

#### Errors

_Errors_ are exceptional conditions 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.

All exceptions in Java that inherit from `Error` are considered errors.
All unchecked exceptions inherit from `RuntimeException`, which itself is an extension of `Exception`.

### Throwing exceptions

Expand Down Expand Up @@ -136,3 +127,14 @@ Withdrawing -10.0
Withdrawal failed: Cannot withdraw a negative amount
Current balance: 5.0
```

### Errors

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.
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.

All errors in Java inherit from the `Error` class.