站内搜索: 请输入搜索关键词

当前页面: 开发资料首页业界新闻J2ee中的异常管理和错误追循..

J2ee中的异常管理和错误追循..

摘要: Javaworld近日有一篇文章的标题是 "J2ee中的异常管理和错误追循",根据文章中提到的,It "provides the basis for developing a set of policies along with a supporting framework for error handling in the J2EE world".. 作者提到了一个概念叫 ap
Javaworld近日有一篇文章的标题是 "J2ee中的异常管理和错误追循",根据文章中提到的,It "provides the basis for developing a set of policies along with a supporting framework for error handling in the J2EE world"..
作者提到了一个概念叫 application-wide user session - 一种可以适用于多个layers的session,比如,web 应用, EJBs, EIS modules,其他 J2EE 组件。

对于作者, 处理异常的要求是:
1.use unchecked exceptions,这样可以给用户更多的选择,当用户使用第三方组件的时候,你并不知道这个组件会使用unchecked exceptions或者checked exceptions,所以你必须用wrapper来将checked exceptions包装成unchecked exceptions。当然,如果使用unchecked exceptions,你将不能强制让用户去处理异常..

2. Encapsulate error handling and install a handler on top of each tier.. 在一个安全的网络环境下,你将可以专注于business layer的异常处理。而hander将会处理剩下的异常:比如 logging, system management notification, transformations 等....

3.Model the exception hierarchy using a "simple living" approach..不要在发现一种新的异常的时候,就创建一个新的exception 类型,你要首先问问自己,你是不是仅仅是遇到了某种异常的变种,然后,用户是否能够处理你创建的异常类型...记住,异常也是objects,在某种意义上来讲,异常的属性, 已经可以描述不同形势下的情况...

4. Give meaningful messages to end users...

作者通过aspects来在不同的layer来添加exception handling...从web到swing或者awt....

这些的实现,都是存在一系列假设前提的,比如:an application-wide session, aspects as exception wrappers, and the doctrine of unchecked exceptions, increasingly common among Java developers...
在J2ee handling中,这的要这样来处理异常吗,如果是的话,generic exception handling solution 将会是什么样的?

原文参考:

http://www.javaworld.com/javaworld/jw-07-2005/jw-0711-exception.html
↑返回目录
前一篇: AspectJ 支持JAVA 5的新特性
后一篇: JBoss发布EJB 3.0实现beta1版本