Java平台有那么多异常了,为什么我们还需要自定义异常。看了一段英文资料,还是没弄明白。贴出来大家共同讨论。1.Do you need an exception type that isn't represented by those in the Java platform?
2.Would it help users if they could differentiate your exceptions from those thrown by classes written by other vendors?
3.Does your code throw more than one related exception?
4.If you use someone else's exceptions, will users have access to those exceptions? A similar question is, should your package be independent and self-contained?
2.Would it help users if they could differentiate your exceptions from those thrown by classes written by other vendors?
3.Does your code throw more than one related exception?
4.If you use someone else's exceptions, will users have access to those exceptions? A similar question is, should your package be independent and self-contained?
answer: yes,do need. sometimes the personal business does require it just like the upper one said.2.Would it help users if they could differentiate your exceptions from those thrown by classes written by other vendors?
answer: yes, it helps. i think if they could differentiate them, it could help them to better understand the situation when the exception occurs.3.Does your code throw more than one related exception?
answer: yes, it does. including those exceptions from the java platform, some of them are related with each other.i think it maybe could inhance the systematic property of the exceptions.it just proves they are integrated into one platform.4.If you use someone else's exceptions, will users have access to those exceptions? A similar question is, should your package be independent and self-contained?
answer: maybe they have not. my package should be independent and self-contained. why? maybe loose coupling makes it.就像楼上说的具体业务的要求,系统异常不可能面面俱到,自定义就是为了在实际中填补应用空白,另外的,自己的一套关联度强的异常可控性高,识别度高,和平台异常搭配使用,满足业务需求和系统需求。
http://book.csdn.net/bookfiles/150/1001506505.shtml
楼主看看这个吧。