throws:
出现在方法头部,表示可能会抛出某些异常
throw:
出现在方法体中,一定会抛出某种异常
Throwable
是java.lang的一个类
public void mathod3()throws SomeException{
throw new SomeException
("SomeExceptions occr in mathod3");
}
在hibernate文档中看见一个throwable
package org.hibernate.tutorial.util;
import org.hibernate.SessionFactory;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
import org.hibernate.cfg.Configuration;
public class HibernateUtil {
private static final SessionFactory sessionFactory = buildSessionFactory();
private static SessionFactory buildSessionFactory() {
try {
// Create the SessionFactory from hibernate.cfg.xml
new Configuration().configure().buildSessionFactory(
new StandardServiceRegistryBuilder().build() );
}
catch (Throwable ex) {
// Make sure you log the exception, as it might be swallowed
System.err.println("Initial SessionFactory creation failed." + ex);
throw new ExceptionInInitializerError(ex);
}
}
public static SessionFactory getSessionFactory() {
return sessionFactory;
}
}
6098

被折叠的 条评论
为什么被折叠?



