当前位置:网站首页>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");
}边栏推荐
- OVSDB
- ARIMA model for time series analysis and prediction
- Como automatic test system: build process record
- 博途PLC一阶滞后系统传递函数阶跃响应输出仿真(SCL)
- Table fix specific rows
- LeetCode剑指offer专项(一)整数
- Brief description of hystrix configuration
- Database foundation
- Open source management system based on ThinkPHP
- 【uniapp】多种支付方式封装
猜你喜欢

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

A tutorial for mastering MySQL database audit characteristics, implementation scheme and audit plug-in deployment

From boosting to lamdamart

The analysis, solution and development of the problem of router dropping frequently

Idea settings set shortcut keys to convert English letters to case in strings

Web page basic label

什么是消息订阅和发布?

Vscode cannot start the problem solving idea

20220209 create a basic Servlet

Now developers are beginning to do testing. Will there be no software testers in the future?
随机推荐
Parameterization of JMeter performance test using CSV file
DADNN: Multi-Scene CTR Prediction via Domain-Aware Deep Neural Network
DCN (deep cross network) Trilogy
Crawler - > tpimgspider
Regression analysis code implementation
TensorFlow学习日记之tflearn
Unity metaverse (II), mixamo & animator hybrid tree and animation fusion
Idea settings set shortcut keys to convert English letters to case in strings
Machine learning related competition website
table 固定特定行
JWT快速入门
利用js实现统计字符串数组中各字符串出现的次数,并将其格式化为对象数组。
Master slave database deployment
Add traceid to the project log
Summarize the common high-frequency interview questions of the software testing post
总结软件测试岗的那些常见高频面试题
Network ()
时间序列分析预测实战之ARIMA模型
深度学习模型部署
Vscode cannot start the problem solving idea