Added a new point on finally keyword! (#18538)
A new point about finally keyword is demonstrated with the help of an example.
This commit is contained in:
committed by
Quincy Larson
parent
0872c911ce
commit
9cd52ab698
@ -17,3 +17,17 @@ try {
|
|||||||
// except when System.exit() is called in "try" or "catch" blocks;
|
// except when System.exit() is called in "try" or "catch" blocks;
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
The finally block does not need the catch block to precede it.There can also be a finally block without the catch block.
|
||||||
|
|
||||||
|
***Example:***
|
||||||
|
```java
|
||||||
|
try {
|
||||||
|
//Normal code
|
||||||
|
System.out.println("hello world!");
|
||||||
|
} finally {
|
||||||
|
System.out.println("In finally block");
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
The above code works fine even though the catch statement is not used.
|
||||||
|
Reference in New Issue
Block a user