Your Ad Here
首页 | 编程语言 | 网站建设 | 游戏天堂 | 冲浪宝典 | 网络安全 | 操作系统 | 软件时空 | 硬件指南 | 病毒相关 | IT 认证
软讯网络 > 编程语言 > Java > 项目中的异常处理2
【标  题】:项目中的异常处理2
【关键字】:
【来  源】:http://blog.csdn.net/xuxiheng/archive/2006/11/13/1382196.aspx

项目中的异常处理2

Your Ad Here

功能:通过seqno查找记录,可能为空,所以要判断。在try块中抛出的异常可以由catch块抓取。

/**
 * 根據seqno查詢臨時表的待審核記錄
 * 
 * 
@param seqno
 *            序號
 * 
@param locale
 *            String
 * 
@return List
 * 
@throws BusiException
 
*/
public List qryBySeqno(long seqno, String locale) throws BusiException {

    ArrayList al 
= null;
    
if (LOG.isDebugEnabled()) {
        LOG.debug(
"[AccountYmService]"
                
+ "[FUNCTION:qryAccountYmData][Param seqno:" + seqno
                
+ "][begin]");
    }

    EntityManager mgr 
= initiate();
    AccountYmTempDao ayTempDao 
= AccountYmTempDao.getInstance(mgr);

    EntityTransaction tx 
= null;
    
try {
        AccountYmVO accountYmVO;
        tx 
= mgr.beginTransaction();

        List list;
        
try {
            list 
= ayTempDao.selectBySeqno(seqno);
        } 
catch (DbAccessException e) {
            LOG.error(
"[FUNCTION:qryBySeqno()]" + "[DbAccessException]", e);
            tx.rollback();
            
throw new BusiException(
                    ExceptionConstant.DATABASE_ACCESS_EXCEPTION, 
"",
                    locale, ExceptionConstant.INFO_TYPE);
        }

        
if (list != null && list.size() > 0) {
            
if (LOG.isDebugEnabled()) {
                LOG.debug(
"[FUNCTION:qryBySeqno()]"
                        
+ "select list success!");
            }

            al 
= new ArrayList();

            AccountYmTemp accountYmTemp;
            
for (int i = 0; i < list.size(); i++) {
                accountYmVO 
= new AccountYmVO();
                accountYmTemp 
= (AccountYmTemp) list.get(i);
                BeanUtils.copyProperties(accountYmVO, accountYmTemp);
                BeanUtils
                        .copyProperties(accountYmVO, accountYmTemp.getId());

                al.add(accountYmVO);
            }

        } 
else {
            
throw new BusiException(
                    ExceptionConstant.NOT_FOUND_SEQNO_IN_TEMP, 
"", locale,
                    ExceptionConstant.INFO_TYPE);
        }
        tx.commit();
    } 
catch (InvocationTargetException e) {
        LOG.error(
                
"[FUNCTION:qryBySeqno()]" + "[InvocationTargetException]",
                e);
        tx.rollback();
        
throw new BusiException(
                ExceptionConstant.INVOCATION_TARGET_EXCEPTION, 
"", locale,
                ExceptionConstant.INFO_TYPE);
    } 
catch (IllegalAccessException e) {
        LOG
                .error(
"[FUNCTION:qryBySeqno()]"
                        
+ "[IllegalAccessException]", e);
        tx.rollback();
        
throw new BusiException(ExceptionConstant.ILLEGAL_ACCESS_EXCEPTION,
                
"", locale, ExceptionConstant.INFO_TYPE);
    } 
catch (BusiException e) {
        
throw e;
    }
    
return al;
}

 

 

异常处理3:JUnit中Assert中要处理调用方法后抛出的异常:【上一篇】
关于Jive中的迭代器与代理模式:【下一篇】
【相关文章】
没有相关文章
【随机文章】
  • 天气
  • linux使用技巧
  • SQL Server 2005:数据类型最大值
  • Printing Usage HOWTO 如何使用打印机-1. 导言
  • 综合业务交换平台实现统一的初衷
  • pfn_pte()
  • 采用POI和ANTLR提取WORD文档数据
  • Linux 核心安装
  • 未整理速达ERP代码 (BCB)
  • 这个司机足够MBA水准!
  • 【相关评论】
    没有相关评论
    【发表评论】
    姓名:
    邮件:
    随机码*
    评论*
          
    |  首 页  |  版权声明  |  联系我们   |  网站地图  |
    CopyRight © 2004-2007 bbb软讯网络 All Rigths Reserved.