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开始,不建议使用这个方法,因为这不能很好地对枚举进行维护,正确应该是利用 ...
随机推荐
- Dancing Link 详解(转载)
Dancing Link详解: http://www.cnblogs.com/grenet/p/3145800.html Dancing Link求解数独: http://www.cnblogs.co ...
- 解决IIS Web部署 svg/woff/woff2字体 404错误
最近在IIS上部署web项目的时候,发现浏览器总是报找不到woff.woff2字体的错误.导致浏览器加载字体报404错误,白白消耗了几百毫秒的加载时间. 一开始以为是路径的问题,检查发现路径也没错. ...
- 重新想象 Windows 8 Store Apps (34) - 通知: Toast Demo, Tile Demo, Badge Demo
[源码下载] 重新想象 Windows 8 Store Apps (34) - 通知: Toast Demo, Tile Demo, Badge Demo 作者:webabcd 介绍重新想象 Wind ...
- 几个gcc的扩展功能
-finstrument-functions constructor destructor __builtin_return_address http://linuxgazette.net/15 ...
- 后缀数组---Milk Patterns
POJ 3261 Description Farmer John has noticed that the quality of milk given by his cows varies from ...
- 管理系统的前端解决方案:Pagurian V1.3发布
Pagurian 一个管理系统的前端解决方案, 致力于让前端设计,开发,测试,发布更简单. 功能简介 Pagurian 适用于Web管理级的项目 基于Sea.js遵循CMD规范,友好的模块定义,使业务 ...
- css实现垂直居中的方法
1,设置其line-height值,使之与其高度相同 2,设置table结构,用vertical-align:middle; 3,应用定位,父级别:position:relative:子级:posit ...
- SharePoint 2013: Search Architecture in SPC202
http://social.technet.microsoft.com/wiki/contents/articles/15989.sharepoint-2013-search-architecture ...
- PowerDesign设置列名与表名的大小写规则
因为设计的Model是要用到Oracle 11g的,Oracle 11g的表名和列名默认是大写,在设计模型当中小写转大写一直很苦闹,发现PowerDedign可以直接设置,见下文: 打开Tools-- ...
- Android中方便好用的倒计时类
一.使用api提供的类进行操作 Android提供了CountDownTimer来让我们进行倒计时,可以让我们很方便的进行倒计时的操作.使用方式也很简单,下面直接贴代码就好了: package ...