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 }}
CPU-Code
java
Repository navigation
Code
Issues
Pull requests
10
(10)
Discussions
Actions
Projects
Wiki
Security and quality
Insights
More
items
Files
Expand file tree
master
Breadcrumbs
java
/
Exception
/
src
/
com
/
cpucode
/
java
/
Exception15.java
Copy path
Blame
More file actions
Blame
More file actions
Latest commit
History
History
History
48 lines (43 loc) · 1.67 KB
master
Breadcrumbs
java
/
Exception
/
src
/
com
/
cpucode
/
java
/
Exception15.java
Copy path
Top
File metadata and controls
Code
Blame
48 lines (43 loc) · 1.67 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
/*
* @由于个人水平有限, 难免有些错误, 还请指点:
* @Author: cpu_code
* @Date: 2020-09-15 09:59:51
* @LastEditTime: 2020-09-15 10:02:40
* @FilePath: \java\Exception\Exception15.java
* @Gitee: [https://gitee.com/cpu_code](https://gitee.com/cpu_code)
* @Github: [https://github.com/CPU-Code](https://github.com/CPU-Code)
* @CSDN: [https://blog.csdn.net/qq_44226094](https://blog.csdn.net/qq_44226094)
* @Gitbook: [https://923992029.gitbook.io/cpucode/](https://923992029.gitbook.io/cpucode/)
*/
package
Exception
;
import
java
.
io
.
FileNotFoundException
;
import
java
.
io
.
IOException
;
public
class
Exception15
{
public
static
void
main
(
String
[]
args
)
throws
IOException
{
try
{
// 可能产生异常的代码
// 当产生异常时,必须有处理方式。要么捕获,要么声明。
read
(
"b.txt"
);
}
catch
(
FileNotFoundException
e
) {
// 实现对捕获到的异常进行处理
//try中抛出的是什么异常,在括号中就定义什么异常类型
System
.
out
.
println
(
e
);
}
finally
{
System
.
out
.
println
(
"都必须执行这"
);
}
System
.
out
.
println
(
"over"
);
}
// 我们 当前的这个方法中 有异常 有编译期异常
public
static
void
read
(
String
path
)
throws
FileNotFoundException
{
if
(!
path
.
equals
(
"a.txt"
)) {
//如果不是 a.txt这个文件
// 我假设 如果不是 a.txt 认为 该文件不存在 是一个错误 也就是异常 throw
throw
new
FileNotFoundException
(
"文件不存在"
);
}
}
}
/*
java.io.FileNotFoundException: 文件不存在
都必须执行这
over
*/
You can’t perform that action at this time.