当前位置:网站首页>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");
}边栏推荐
- Shardingsphere data slicing
- A tutorial for mastering MySQL database audit characteristics, implementation scheme and audit plug-in deployment
- The difference between ArrayList and LinkedList
- C# 使用Log4Net记录日志(基础篇)
- 2022.7.22DAY612
- Practice of online question feedback module (XIV): realize online question answering function
- OVS underlying implementation principle
- MySQL implementation plan
- 0 dynamic programming leetcode1567. Length of the longest subarray with positive product
- PyTorch
猜你喜欢

Network ()

What is bloom filter in redis series?

Lambda and stream

Wrong Addition

Network trimming: a data driven neuron pruning approach towards efficient deep architectures paper translation / Notes

Establishment and use of openstack cloud platform

Regression analysis code implementation

Wrong Addition

Basic knowledge of convolutional neural network

JWT快速入门
随机推荐
总结软件测试岗的那些常见高频面试题
2021-11-09
ShardingSphere数据分片
JWT快速入门
Learning Efficient Convolutional Networks Through Network Slimming
System architecture & microservices
Machine learning related competition website
Speech at 2021 global machine learning conference
"Door lock" ignites a heated discussion on the safety of living alone. The new poster picture is suffocating
Dynamic performance view overview
table 固定特定行
C# 使用Log4Net记录日志(基础篇)
Web page basic label
时间序列分析预测实战之ARIMA模型
Summary of common methods of string
2022.7.22DAY612
Command line execution and test report generation of JMeter performance test
Abnormal (2)
Hcip--- MPLS detailed explanation and BGP route filtering
Database foundation