Effective Java 60 Favor the use of standard exceptions
Benefits to reuse preexisting exceptions
- It makes your API easier to learn and use.
- Programs using your API are easier to read.
- Fewer exception classes mean a smaller memory footprint and less time spent loading classes.
Common Exceptions
Exception |
Occasion for Use |
IllegalArgumentException |
Non-null parameter value is inappropriate |
IllegalStateException |
Object state is inappropriate for method invocation |
NullPointerException |
Parameter value is null where prohibited |
IndexOutOfBoundsException |
Index parameter value is out of range |
ConcurrentModificationException |
Concurrent modification of an object has been detected where it is prohibited |
UnsupportedOperationException |
Object does not support method |
Principle
- Reuse must be based on semantics, not just on name.
- Also, feel free to subclass an existing exception if you want to add a bit more failure-capture information (Item 63).
Effective Java 60 Favor the use of standard exceptions的更多相关文章
- Effective Java 16 Favor composition over inheritance
Inheritance disadvantage Unlike method invocation, inheritance violates encapsulation. Since you don ...
- Effective Java 26 Favor generic types
Use generic types to replace the object declaration Add one or more type parameters to its declarati ...
- Effective Java 27 Favor generic methods
Static utility methods are particularly good candidates for generification. The type parameter list, ...
- Effective Java 59 Avoid unnecessary use of checked exceptions
The burden is justified if the exceptional condition cannot be prevented by proper use of the API an ...
- Effective Java Index
Hi guys, I am happy to tell you that I am moving to the open source world. And Java is the 1st langu ...
- 《Effective Java》读书笔记 - 9.异常
Chapter 9 Exceptions Item 57: Use exceptions only for exceptional conditions 这条item的意思就是,千万不要用except ...
- Effective Java 目录
<Effective Java>目录摘抄. 我知道这看起来很糟糕.当下,自己缺少实际操作,只能暂时摘抄下目录.随着,实践的增多,慢慢填充更多的示例. Chapter 2 Creating ...
- 【Effective Java】阅读
Java写了很多年,很惭愧,直到最近才读了这本经典之作<Effective Java>,按自己的理解总结下,有些可能还不够深刻 一.Creating and Destroying Obje ...
- Effective Java通俗理解(下)
Effective Java通俗理解(上) 第31条:用实例域代替序数 枚举类型有一个ordinal方法,它范围该常量的序数从0开始,不建议使用这个方法,因为这不能很好地对枚举进行维护,正确应该是利用 ...
随机推荐
- 基于HTML5技术的电力3D监控应用(四)
回答了知乎问题较长,一些使用WebGL的经验,作为新的一篇: 正好逛到这个问题,正好是2013年底,正好最近基于的HT for Web 3D做的电力项目收尾,正好用到的就是WebGL技术,因此说说自己 ...
- JS魔法堂:IE5~9的Drag&Drop API
一.前言 < HTML5魔法堂:全面理解Drag & Drop API>中提到从IE5开始已经支持DnD API,但IE5~9与HTML5的API有所不同,下面我们来了解一 ...
- [团队项目]expat不兼容BUG
本周五软工团队项目的第一次前后端全部对接时,出了一个蛋疼的错误. 最初起因是小丽叔出于安全的考虑,使用守护进程来跑Web服务器.守护进程(Daemon)是运行在后台的一种特殊进程,如果服务器用root ...
- sprint3(第三天)
今天在做的任务是整合前台和后台,使前台可以从后台得到数据 燃尽图:
- WCF小结
WCF总结 1.WCF(原代号为Indigo)是一个用于创建和运行分布式系统的技术集合,使用它能创建安全的.可靠的.跨平台的的分布式解决方案.它的面向服务的编程模型,整合了.Net平台下以往全部的分布 ...
- csharp:Compare two DataTables to rows in one but not the other
/// <summary> /// 账面数据 Accounting /// </summary> /// <returns></returns> Dat ...
- 不要迷恋那些没技术含量的Linux发行版
昨天悲剧了,重装系统,一个手贱点了替换原系统,分区全给删了,将近三天的工作成果没有了.
- struts2 java.lang.StackOverflowError org.apache.struts2.json.JSONWriter
1. 问题描述: 页面通过异步访问action, action的方法通过map封装数据,struts的result的type设置为json,后台报错 六月 25, 2016 6:54:33 下午 ...
- linux 常用技巧
1--查看版本 查看内核版本 # cat /proc/version 查看linux版本 # lsb_release -a或者 cat /etc/issue 2--linux服务器测速 speedte ...
- phantomjs 另类用法
这几天接到了一个数据采集的项目 通过对网站的前期分析得到以下内容 1.网站本身采用.NET开发 2.需抓取内容采用DES加密 虽然得到了前端javascript的加解密算法,但大家也知道跨语言算法想要 ...