当前位置:网站首页>The difference between throw and throws?
The difference between throw and throws?
2022-07-26 07:53:00 【I like iced black tea】
Throw:
1, Acting in the method body , Indicates that a specific exception is thrown , Handled by statements inside the method
2, Specific outward throwing action , So what it throws is an exception entity class . If you execute throw It must have thrown some specific exception object
3,Throw The exception thrown means that such an exception must occur .
public static void testThrow(Integer n) {
if (n == null) {
throw new NullPointerException();// Runtime exceptions do not need to be declared on methods
}
}
Throws:
1, Acts on the declaration of a method , If an exception is thrown , The caller of this method will handle the exception .
2, The main statement is that this method will throw some kind of exception , Let its users know the type of exception caught
3,Throws The exception thrown may happen , But it doesn't necessarily happen .
public static byte[] toGBK(String s) throws UnsupportedEncodingException {
return s.getBytes("GBK");
}边栏推荐
- Hcip--- MPLS detailed explanation and BGP route filtering
- Yaml language-01 (data type, array, object)
- Idea shortcut key
- 基于Thinkphp的开源管理系统
- Interview question set
- 2019 ZTE touyue · model compression scheme
- 【uniapp】多种支付方式封装
- Practice of online question feedback module (XIV): realize online question answering function
- 时间序列分析预测实战之ARIMA模型
- Unity Metaverse(二)、Mixamo & Animator 混合树与动画融合
猜你喜欢

基于Thinkphp的开源管理系统

Crawler - > tpimgspider

C# 使用Log4Net记录日志(基础篇)

Logical volume management (LVM)

记一次路由器频繁掉线问题的分析、解决与发展

Devaxpress.xtraeditors.datanavigator usage

Hcip--- MPLS detailed explanation and BGP route filtering

How to ensure the double write consistency between cache and database?

System architecture & microservices

Program environment and pretreatment
随机推荐
2022.7.22DAY612
Wrong Addition
Use js to count the number of occurrences of each string in the string array, and format it into an object array.
“尝鲜”元宇宙,周杰伦最佳拍档方文山将于7月25日官宣《华流元宇宙》
模型剪枝三:Learning Structured Sparsity in Deep Neural Networks
Program environment and pretreatment
机器学习相关比赛网站
动态性能视图概述
总结软件测试岗的那些常见高频面试题
系统架构&微服务
Solution to the problem of token loss when microservice feign is called
Audio and video learning (10) -- PS streaming
Learning Efficient Convolutional Networks Through Network Slimming
Unity metaverse (II), mixamo & animator hybrid tree and animation fusion
From boosting to lamdamart
JWT快速入门
ARIMA model for time series analysis and prediction
AQS implementation principle
Command line execution and test report generation of JMeter performance test
力扣(LeetCode)206. 反转链表(2022.07.25)