Skip to content
Navigation Menu
Sign in
Products
Platform
GitHub
Repository hosting, code review, and collaboration
Copilot
AI coding agent for tasks, projects, and automated work
Build & Ship
Actions
CI/CD and automation
Code Quality
Quality analysis, fixes, and enforcement
Codespaces
Cloud development environments
Secure
Code Security
Vulnerability detection and remediation
Secret Protection
Secret scanning and leak prevention
All Features
Developers
Learn
Documentation
Training
Certifications
Build
Build with Copilot
Customize Copilot
Integrations
Explore
Trending repos
GitHub Sponsors
Developer articles
Changelog
Changelog
Your source for the latest features, improvements, and fixes across GitHub products, all in one place.
Businesses
By Stage
Enterprises
Team
Startups
Nonprofits
By Industry
Healthcare
Financial services
Manufacturing
Government
See all industries
Evaluate GitHub
Why GitHub
Customer Stories
Business insights
Trust Center
Add-ons
GitHub Advanced Security
Enterprise-grade code security
Copilot for business
Enterprise-grade AI features
Premium Support
Enterprise-grade 24/7 support
Resources
Learn & Connect
Documentation
Resource center
Blog
Events & webinars
Community Forum
Customer Stories
Integrations
Support
Customer support
Training
GitHub Status
Company
About
Partners
Changelog
GitHub Universe
GitHub Universe
The event for developers, by developers — talks, workshops, and what’s next for GitHub.
Pricing
Search
/
Sign in
Sign up
Appearance settings
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
Dismiss alert
{{ message }}
java-liu
alibabaStudy
Repository navigation
Code
Issues
Pull requests
9
(9)
Actions
Projects
Security and quality
Insights
More
items
Files
Expand file tree
master
Breadcrumbs
alibabaStudy
/
src
/
main
/
java
/
com
/
exceptions
/
Test.java
Copy path
Blame
More file actions
Blame
More file actions
Latest commit
History
History
History
57 lines (55 loc) · 1.61 KB
master
Breadcrumbs
alibabaStudy
/
src
/
main
/
java
/
com
/
exceptions
/
Test.java
Copy path
Top
File metadata and controls
Code
Blame
57 lines (55 loc) · 1.61 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package
com
.
exceptions
;
/**
* @author Liuys
* @version V1.0
* @Package com.exceptions
* @date 2020/1/17 10:13
* try catch finally组合方式:
* 1、try catch:对代码进行异常检测,并对检测的异常传递给catch处理。异常捕获处理
* void show(){//不需要throws
* try{
* throw new Exception();
* }catch(Exception e){
*
* }
* }
* 2、try finally:对代码进行异常检测,检测到异常后因为没有catch,所以一样会被默认jvm抛出。
* 异常是没有捕获处理的。但是功能所开启的资源需要进行关闭,所以有finally。只为关闭资源。(或者释放资源)
* void show() throws Exception{
* try{
* throw new Exception();
* }finally{
*
* }
* }
* 3、try catch finally
* 检测异常,并传递给catch处理,并关闭资源
* 4、try catch1 catch2 catch3
* */
public
class
Test
{
public
static
void
main
(
String
[]
args
){
Demo4
d
=
new
Demo4
();
System
.
out
.
println
(
d
.
show
(
4
));
}
}
/***
* 1、return返回之前会执行finally(不论是否出现异常)
* 2、如果return放在finally中,那么最后返回的值就是finally中的值
*/
class
Demo4
{
int
show
(
int
num
){
try
{
if
(
num
<
0
){
throw
new
Exception
();
}
return
10
;
}
catch
(
Exception
e
){
System
.
out
.
println
(
e
.
toString
());
//System.exit(0); //退出jvm虚拟机,finally也不会执行
return
200
;
}
finally
{
System
.
out
.
println
(
"finally run"
);
//return 100;
}
}
}
You can’t perform that action at this time.