Be specific in throws clause
来源:互联网 发布:大华监控怎么连接网络 编辑:程序博客网 时间:2024/04/29 04:05
http://www.javapractices.com/topic/TopicAction.do?Id=27
In the throws clause of a method header, be as specific as possible. Do not group together related exceptions in a generic exception class - that would represent a loss of possibly important information.
An alternative is the exception translation practice, in which a low level exception is first translated into a higher level exception before being thrown out of the method.
Example
Here, both IOException and FileNotFoundException are incorrectly lumped together as Exception.
import java.io.*;import java.util.*;public final class BadGenericThrow { //..elided /** * BAD: This method throws a generic Exception, instead * of FileNotFoundException and IOException. */ public void makeFile() throws Exception { //create a Serializable List List<String> quarks = new ArrayList<>(); quarks.add("up"); quarks.add("down"); quarks.add("strange"); quarks.add("charm"); quarks.add("top"); quarks.add("bottom"); //serialize the List try ( ObjectOutputStream output = new ObjectOutputStream( new FileOutputStream("quarks.ser") ) ){ output.writeObject(quarks); } }}
0 0
- Be specific in throws clause
- ORA-38104: Columns referenced in the ON Clause cannot be updated: "U"."USER_ID"
- there can be only one TIMESTAMP column with CURRENT_TIMESTAMP in DEFAULT or ON UPDATE clause
- there can be only one TIMESTAMP column with CURRENT_TIMESTAMP in DEFAULT or ON UPDATE clause
- for clause in Java
- Mysql Specific in Appfuse
- Avoid @throws in javadoc
- 数据库建表 there can be only one TIMESTAMP column with CURRENT_TIMESTAMP in DEFAULT or ON UPDATE clause
- java编程之Noncompliant; %n should be used in place of \n to produce the platform-specific line separato
- jasper reports - parameters for ‘in clause’
- Unknown column 'rownum' in 'where clause'解决方案
- Column 'id' in where clause is ambiguous
- Column 'id' in where clause is ambiguous
- PreparedStatement In Clause 和 Spring JdbcTemplate
- Unknown column '安妮宝贝' in 'where clause'
- JDBC PreparedStatement IN clause alternative approaches
- SQL IN Clause 1000 item limit
- Column 'id' in where clause is ambiguous
- Android binder -- Binder应用实例
- Avoid @throws in javadoc
- 关系型数据库与面向对象的冲突
- AppleScript学习笔记(六)处理程序Handler
- Avoid empty catch blocks
- Be specific in throws clause
- python安装及插件安装
- SICILY 1129. ISBN
- Beware of unknown root causes
- 傀儡进程内存Dump
- linux下fcitx输入法安装
- hdu 3954 Level up 线段树特殊更新节点
- Android binder -- Binder机制编程
- Activity的几种启动方式