Home > Java > javaTutorial > Code examples about the finally keyword in Java

Code examples about the finally keyword in Java

Y2J
Release: 2017-05-03 14:43:13
Original
1660 people have browsed it

java keyword finally Regardless of whether an exception occurs, the finally clause is always executed before the block is completed. The following is an introduction to the Java keyword finally related knowledge through the implementation code. Friends who need it can refer to it

1. If there is no exception after executing the try block, continue to run the statements in the finally block, even if the try block passes Return, break, or continue exits after the last statement, and the statements in finally will also be executed.

Summary:

Regardless of whether an exception occurs, the finally clause is always executed before the block is completed.

Code:

import java.util.Scanner;
public class pideByTwo{
public static void main(String args[]){
Scanner in=new Scanner(System.in);
int x;
System.out.println("please enter integer:");
try{
String oneline=in.nextLine();
x=Integer.ParseInt(oneLine);
System.out.println("half of x is"+(x/2));
}
catch(NumberFormatException e){
System.out.println(e);
} 
finally{
System.out.println("hello world!");
}
}
}
Copy after login

The above is the detailed content of Code examples about the finally keyword in Java. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
Install JAVA
From 1970-01-01 08:00:00
0
0
0
Unable to install java
From 1970-01-01 08:00:00
0
0
0
Can java be used as the backend of the web?
From 1970-01-01 08:00:00
0
0
0
Is this in Java language?
From 1970-01-01 08:00:00
0
0
0
Help: JAVA encrypted data PHP decryption
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template