惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

WordPress大学
WordPress大学
T
Threatpost
阮一峰的网络日志
阮一峰的网络日志
美团技术团队
F
Fortinet All Blogs
The GitHub Blog
The GitHub Blog
月光博客
月光博客
V
Visual Studio Blog
T
Tailwind CSS Blog
Stack Overflow Blog
Stack Overflow Blog
博客园 - 聂微东
Jina AI
Jina AI
J
Java Code Geeks
Martin Fowler
Martin Fowler
大猫的无限游戏
大猫的无限游戏
Recorded Future
Recorded Future
C
Check Point Blog
腾讯CDC
N
Netflix TechBlog - Medium
aimingoo的专栏
aimingoo的专栏
罗磊的独立博客
Hacker News: Ask HN
Hacker News: Ask HN
SecWiki News
SecWiki News
博客园 - Franky
Hacker News - Newest:
Hacker News - Newest: "LLM"
N
News | PayPal Newsroom
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
S
Security @ Cisco Blogs
W
WeLiveSecurity
The Last Watchdog
The Last Watchdog
Cloudbric
Cloudbric
F
Full Disclosure
The Cloudflare Blog
Y
Y Combinator Blog
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
Recent Commits to openclaw:main
Recent Commits to openclaw:main
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Google DeepMind News
Google DeepMind News
MongoDB | Blog
MongoDB | Blog
S
Schneier on Security
Schneier on Security
Schneier on Security
Spread Privacy
Spread Privacy
L
LINUX DO - 热门话题
AI
AI
N
News and Events Feed by Topic
T
Tor Project blog
P
Palo Alto Networks Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
H
Hackread – Cybersecurity News, Data Breaches, AI and More
G
Google Developers Blog

博客园 - 小墨的童鞋

python计算月份的加减 git操作中出现Unlink of file '......' failed. Should I try again? IDEA建立Spring MVC Hello World 详细入门教程 IDEA手工添加webapp目录 解决错误:Your ApplicationContext is unlikely to start due to a @ComponentScan of the default package. IDEA编译时出现 Information:java: javacTask: 源发行版 1.8 需要目标发行版 1.8 发票打印不全不完整的解决方案(Win10) Idea checkstyle插件的使用 .Net转Java.08.format 修复恢复"可疑"的SQLServer数据库 .Net转Java.07.IDEA和VS常用操作、快捷键对照表 .Net转Java.06.字符串的split的区别 .Net转Java.05.为啥MySQL没有nolock .Net转Java.04.踩到switch的坑 通过IntelliJ IDEA和Maven命令查看某个jar包是怎么引入的 .Net转Java.02.数据类型 .Net转Java.01.从Main(main)函数说起 IDEA下Maven的Offline Mode 修改Arduino IDE默认字体
.Net转Java.03.受查异常和非受查异常
小墨的童鞋 · 2018-01-08 · via 博客园 - 小墨的童鞋

转到Java以后发现一个很妖的事情,为啥有些方法后边有个 throws XXXXException

比如下面的代码

    @Override
    public <T> ResponseEntity<T> exchange(String url, HttpMethod method,
            HttpEntity<?> requestEntity, Class<T> responseType, Object... uriVariables) throws RestClientException {

        RequestCallback requestCallback = httpEntityCallback(requestEntity, responseType);
        ResponseExtractor<ResponseEntity<T>> responseExtractor = responseEntityExtractor(responseType);
        return execute(url, method, requestCallback, responseExtractor, uriVariables);
    }

这个是.NET没有的一个语法,受查异常

 

这是摘自《Java核心技术》的解释,我感觉很明确了

Java语言规范将派生于Error类和RuntimeException类的所有异常称为非受查(unchecked)异常【上图中的绿色部分】,所有其他的异常称为受查(checked)异常【上图中的蓝色部分】

编译器将核查是否为所有受查异常提供了异常处理器。

受查异常要么方法内部处理,要么通过方法的声明,提示调用方处理(比如文件找不到等情况)

非受查异常要么不可控制(比如OOM),要么避免发生,其实理论上也是完全可以避免发生的(比如空引用的情况)