3

次のようなクラスがあります。PMD ルールを実行すると、 type の PMD Alert が発生しAvoidThrowingRawExceptionTypesます。コンストラクターの throws 句に他の例外タイプを追加するとエラーが発生するため、これを解決できません

new PersistenceManager(CommonConstants.IP_DB)

これを解決するには?誰でもこれについて私を助けることができますか?.

public class PersistenceManager implements CommonConstants {
.....

/**
     * Stores the persistence mgr for IPMasterData_DB
     */
    public static PersistenceManager IPMasterData_DB  = new PersistenceManager(
                                                              CommonConstants.IP_DB);
     /**
             * Configures the data source according to the resource passed.
             * 
             * @param dbName
             *        Databasename
             */
            protected PersistenceManager(String dbName) throws Exception{
                String resourceName = "";
                if (LOGGER == null) {
                    LOGGER = Logger.getLogger(PersistenceManager.class);
                }
                try {

                    resourceName = getConfigFileName(dbName);

                    this.sessionFactory = new Configuration().configure(resourceName)
                            .setProperty("hibernate.jdbc.batch_size",
                                    PersistenceManager.getBatchSize(dbName))
                            .buildSessionFactory();
                } catch (HibernateException ex) {
                    ex.printStackTrace();
                    LOGGER
                            .error("Exception building SessionFactory for configKey ",
                                    ex);
                    throw new RuntimeException(ErrorConstants.SESSIONFACTORY_BUILD, ex);
                }
            }
}
4

3 に答える 3

4

一般的な例外ではなく特殊な例外をスローすることは、優れたプログラミング手法です。PMDこれを検出してアドバイスすることができます。これはまさに行われたことです。

のインスタンスをスローするのではなく、特殊な例外で例外をラップしてスローしますRuntimeException

于 2012-08-22T14:30:31.760 に答える
1

私が理解しているように、PMD は throws 句ではなくthrow new RuntimeException(... throws 節をそのままにしておくことができますが、新しい (より具体的な) RuntimeException をスローします。

于 2013-05-08T06:58:56.053 に答える