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
/
MyException.java
Copy path
Blame
More file actions
Blame
More file actions
Latest commit
History
History
History
34 lines (33 loc) · 1.58 KB
master
Breadcrumbs
alibabaStudy
/
src
/
main
/
java
/
com
/
exceptions
/
MyException.java
Copy path
Top
File metadata and controls
Code
Blame
34 lines (33 loc) · 1.58 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
package
com
.
exceptions
;
/**
* @author Liuys
* @version V1.0
* @Package com.exceptions
* @date 2020/1/15 16:07
* @description
* 1.RuntimeException是那些可能在Java虚拟机正常运行期间抛出的异常的超类,
* 可能在执行方法期间抛出但未被捕获的 RuntimeException的任何子类都无需在 throws 子句中进行声明。
* 为什么抛出RuntimeException,不需要捕获,不要声明呢?
* 不是功能本身发生的异常,而是因为比如调用者传递参数错误而导致功能运行失败,
* 这时也是问题,需要通过异常来体现,但是这个异常不要声明出来的。
* 声明的目的是为了让调用者进行处理。
* 不声明的目的是不让调用者进行处理,就是为了让程序停止,让调用者看到现象,并进行代码的修正。
*
*
*原理异常分两种:
* 1、编译时异常:编译器会检测的异常
* 2、运行时异常:编译器不会检测的异常,不需要声明。声明也可以,如果声明了,无外乎就是让调用者给出处理方式。
*throw和throws的区别:
* 1、throw用在函数内。throws用在函数上。
* 2、throw抛出的异常对象。 throws用于进行异常类的声明,后面异常类可以有多个,用逗号隔开。
*/
public
class
MyException
extends
RuntimeException
{
//定义构造函数
public
MyException
(){
super
();
}
public
MyException
(
String
message
){
//如果自定义异常需要异常信息,可以通过调用父类的带有字符串参数的构造函数即可
super
(
message
);
}
}
You can’t perform that action at this time.