try is a keyword in Java, mainly used for exception handling mechanism, so what does it do?
try – used for listening. Place the code to be monitored (code that may throw exceptions) within the try statement block. When an exception occurs within the try statement block, the exception is thrown.
It is generally used in combination with the catch..finally block to guide the first part of the keyword and is used to declare the exception that needs to catch the specified statement block.
The complete usage method is:
try { 语句块1 } catch ( extends Throwable> e) { 语句块2.1 } catch ( extends Throwable> e) { 语句块2.2 } catch ( extends Throwable> e) { 语句块2.3 ... } finally { 语句块3 }
catch can appear 0, 1 or more times, finally can appear 0 or 1 times, but catch and finally They cannot both appear at the same time.
Example:
public class Test { public static void main(String[] args) { int i = 10; try { System.out.println(i / 0);//会出现异常 } catch(ArithmeticException ame) { ame.printStackTrace(); } finally { System.out.println("byebye"); } } }
Related learning recommendations: java basic tutorial
The above is the detailed content of What does try mean in java. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

SublimeText3 Chinese version
Chinese version, very easy to use