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
/
Demo.java
Copy path
Blame
More file actions
Blame
More file actions
Latest commit
History
History
History
39 lines (37 loc) · 1.35 KB
master
Breadcrumbs
alibabaStudy
/
src
/
main
/
java
/
com
/
exceptions
/
Demo.java
Copy path
Top
File metadata and controls
Code
Blame
39 lines (37 loc) · 1.35 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
package
com
.
exceptions
;
/**
* @author Liuys
* @version V1.0
* @Package com.exceptions
* @date 2020/1/16 9:50
* 1、声明和捕获
* (1)声明:将问题标识出来,报告给调用者
* 如果函数内能过throw抛出了编译时异常,而捕获,那么必须通过throws进行声明,让调用者去处理
* (2)捕获:java中对异常有针对性的语句进行捕获。
* try{
* //需要被检测的语句
* }catch(异常类 变量){
* //异常的处理语句
* }finally{
* //一定会被执行的语句
* }
*
* 如果定义功能时有问题发生需要报告给调用者,可以通过在函数上使用throws关键字进行声明
*/
public
class
Demo
{
public
static
void
main
(
String
[]
args
)
//2、或者捕获 throws Exception//1、在调用者上声明
{
ExceptionDemo1
d1
=
new
ExceptionDemo1
();
try
{
d1
.
show
();
//当调用了声明异常的方法时,必须有处理方式,要么捕获,要么声明
}
catch
(
Exception
e
){
//Exception e = new Exception()、括号中需要定义什么呢?对方抛出的是什么问题,在括号中就定义什么问题的引用
System
.
out
.
println
(
"异常发生了!"
);
}
System
.
out
.
println
(
"Hello World!"
);
}
}
class
ExceptionDemo1
{
void
show
()
throws
Exception
{
throw
new
Exception
();
}
}
You can’t perform that action at this time.