类型DataAccessException异常不能抛出;一个异常类型必须是Throwable的一个子类 [英] No exception of type DataAccessException can be thrown; an exception type must be a subclass of Throwable

查看:5386
本文介绍了类型DataAccessException异常不能抛出;一个异常类型必须是Throwable的一个子类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的源代码如下。
它有一个错误,可以抛出DataAccessException类型的异常;异常类型必须是Throwable的子类。

My source code like below. It has a error, "No exception of type DataAccessException can be thrown; an exception type must be a subclass of Throwable".

我无法理解为什么错误ocurrs。
让我知道。 thx。

I can't understand why the error ocurrs. let me know. thx.

package com.sds.afi.cosmos.cmm.db.impl;

import java.sql.SQLException;
import java.util.HashMap;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DataAccessException;
import org.springframework.orm.ibatis.SqlMapClientTemplate;
import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport;
import org.springframework.stereotype.Repository;

import com.sds.afi.cosmos.cmm.db.MainDao;

@Repository
//@SuppressWarnings("unchecked")   // 부적절한 컴파일러의 경고를 제거
public class MainDaoImpl extends SqlMapClientDaoSupport  implements MainDao {

    @Autowired
    private SqlMapClientTemplate sqlMapClientTemplate;

    @SuppressWarnings("unchecked")
    @Override
    public List<HashMap> getUserInfo() throws DataAccessException {

        List<HashMap> lists;

        lists = sqlMapClientTemplate.queryForList("common.getList");

        return lists;
    }

}


推荐答案

如果异常的类型层次结构中的某个类不在类路径上,则可能会发生这种情况。在这种情况下,它不可能验证异常是否真的扩展Throwable,无论是否被检查,等等。因此错误。例如Dataaccessexception的超类:NestedRuntimeException可能从类路径中丢失,因为它位于不同的jar,即spring-core。

This can happen if some class in the type-hierarchy of the exception is not on the class-path. In that case, its not possible to verify whether the exception really extends Throwable, whether it is a checked one or not, etc. Hence the errors. e.g superclass of Dataaccessexception : NestedRuntimeException may be missing from the class-path as it is in a differnt jar i.e. spring-core.

这篇关于类型DataAccessException异常不能抛出;一个异常类型必须是Throwable的一个子类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆