为嘛static块中try catch必须抛呢
public class TestHibernate {
private static final SessionFactory sessionFactory;
static{
try {
sessionFactory = new Configuration().configure().buildSessionFactory();
} catch (HibernateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
throw new HibernateException(e.getMessage());
}
}
}
如果我不写throw new HibernateException(e.getMessage());eclipse编译private static final SessionFactory sessionFactory;这行就会报错,报错如下:
Multiple markers at this line
- The value of the field TestHibernate.sessionFactory is
not used
- The blank final field sessionFactory may not have been
initialized
请高人指点下下
[解决办法]
Multiple markers at this line
- The value of the field TestHibernate.sessionFactory is
not used
- The blank final field sessionFactory may not have been
initialized
提示说的很明白,sessionFactory 没有被初始化,因为如果发生异常,而你在异常里未做任何处理,sessionFactory 就不会赋值
[解决办法]