我有时会看到
try {
} catch(Throwable e) {
}
Run Code Online (Sandbox Code Playgroud)
而有时
try {
} catch(Exception e) {
}
Run Code Online (Sandbox Code Playgroud)
有什么不同
赶上是不好的做法Throwable?
例如这样的事情:
try {
// Some code
} catch(Throwable e) {
// handle the exception
}
Run Code Online (Sandbox Code Playgroud)
这是一种不好的做法还是我们应该尽可能具体?
为什么catch(Exception)几乎总是一个坏主意?
鉴于:Throwable是Exception超级.
当我编写自己的"例外"读课文,我看到的例子Throwable中所使用catch的块和其他经文显示new Exception() 在正在使用catch块.我还没有看到何时应该使用每个的解释.
我的问题是,什么时候应该Throwable使用,什么时候应该new Exception()使用?
使用以下任一内部catch或else块内:
throw throwable;
Run Code Online (Sandbox Code Playgroud)
要么
throw new Exception();
Run Code Online (Sandbox Code Playgroud) 所以我试图让我的Java应用程序通过用于SQL Server的
Microsoft JDBC驱动程序4.0连接到SQL Server 2012 ,并且一切似乎进展顺利但是hibernate只是不断回来NullExceptions并且不会执行任何内容try/catch(因此的NullException),我完全不知道为什么.这是来自运行hibernate的netbeans console()的pastebine.getMessage()(出于这个问题的目的,我正在使用一个名为的示例表prime_table).
在pastebin日志中,你会注意到......
2013年2月11日下午5:21:04 org.hibernate.cfg.Configuration doConfigure INFO:已配置的SessionFactory:null
关于为什么会发生这种情况的任何想法?(我不确定,但它可能与整体堆栈跟踪有关).
其他日志(在JSP构建期间)
所有日志将在2013年3月中旬或3月下旬之前提供
资源,我一直在读
预配置的Netbeans项目设置 commandline: tree /f
netbeans http://iforce.co.nz/i/llroxgez.s5s.png
Hibernate.cfg.xml(Hari"hibernate.cache.provider_class"建议添加)
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="hibernate.cache.provider_class">org.hibernate.cache.HashtableCacheProvider</property>
<property name="hibernate.connection.driver_class">com.microsoft.sqlserver.jdbc.SQLServerDriver</property>
<property …Run Code Online (Sandbox Code Playgroud) 如果这是一个愚蠢的问题,请原谅我,但据我所知,必须捕获并处理所有Java异常.例如,像这样会产生编译器错误:
public String foo(Object o) {
if (o instanceof Boolean) {
throw new Exception();
}
return o.toString();
}
Run Code Online (Sandbox Code Playgroud)
因为该方法foo()没有添加throws子句.
然而,这个例子将工作(除非是方法foo()没有一个throws条款或方法bar()没有环绕的使用foo()中try/catch块):
public String foo(Object o) throws Exception {
if (o instanceof Boolean) {
throw new Exception();
}
return o.toString();
}
public void bar(Object o) {
try {
String s = foo(o);
}
catch (Exception e) {
//...
}
//...
}
Run Code Online (Sandbox Code Playgroud)
最后,有时Java程序有时会由于未处理的异常而崩溃.
这是怎么发生的?
好的!所以我在Windows 8上使用硒铬驱动程序(32位).
我已将隐式等待设置如下:
DesiredCapabilities des=DesiredCapabilities.chrome();
ChromeOptions options = new ChromeOptions();
options.addArguments("window-size=1366,768");
des.setCapability(ChromeOptions.CAPABILITY, options);
dvr= new ChromeDriver(des);
driver = new EventFiringWebDriver(dvr);
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
Run Code Online (Sandbox Code Playgroud)
但在我的测试的某些时候,我得到一个staleElementException ...如下所示:
我并不太担心staleElementException,困扰我的是异常中的以下行:命令持续时间或超时:14毫秒
当超时已经隐含地设置为30秒时,为什么我得到14毫秒的超时....任何建议或解决方法将是appreaciate谢谢!
public static WebElement grabElementByPureXPath(String xpath)
{
WebElement element = null;
int attempts=1;
try
{
while(attempts<7)
{
try
{
element=driver.findElement(By.xpath(xpath));
}
catch(StaleElementReferenceException e){}
attempts++;
}
}
catch(Throwable t)
{
try
{
element=driver.findElement(By.cssSelector(xpath));
}
catch(Throwable T)
{
takeScreenShot(xpath);
Assert.assertTrue(t.getMessage(),false);
}
}
return element;
}
Run Code Online (Sandbox Code Playgroud)
<-----------------------以下例外情况----------------------- ---------------------->
org.openqa.selenium.StaleElementReferenceException: stale element reference: element is not attached …Run Code Online (Sandbox Code Playgroud)