相关疑难解决方法(0)

271
推荐指数
5
解决办法
18万
查看次数

抓住Throwable是不好的做法?

赶上是不好的做法Throwable

例如这样的事情:

try {
    // Some code
} catch(Throwable e) {
    // handle the exception
}
Run Code Online (Sandbox Code Playgroud)

这是一种不好的做法还是我们应该尽可能具体?

java exception-handling throwable

100
推荐指数
10
解决办法
8万
查看次数

59
推荐指数
6
解决办法
2万
查看次数

什么时候应该使用Throwable而不是新的Exception?

鉴于:ThrowableException超级.

当我编写自己的"例外"读课文,我看到的例子Throwable中所使用catch的块和其他经文显示new Exception() 在正在使用catch块.我还没有看到何时应该使用每个的解释.

我的问题是,什么时候应该Throwable使用,什么时候应该new Exception()使用?

使用以下任一内部catchelse块内:

throw throwable;
Run Code Online (Sandbox Code Playgroud)

要么

throw new Exception();
Run Code Online (Sandbox Code Playgroud)

java exception throwable

41
推荐指数
4
解决办法
9万
查看次数

预先配置的netbeans项目与NoSuchMethodError hibernate和spring冲突

所以我试图让我的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 spring netbeans hibernate jdbc

7
推荐指数
1
解决办法
782
查看次数

当必须始终捕获异常时,Java程序如何崩溃?

如果这是一个愚蠢的问题,请原谅我,但据我所知,必须捕获并处理所有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程序有时会由于未处理的异常而崩溃.

这是怎么发生的?

java exception-handling exception

5
推荐指数
1
解决办法
355
查看次数

除RuntimeException之外的异常

除了Java中的RuntimeException之外,是否有可能发生异常?谢谢.

java exception

2
推荐指数
2
解决办法
2628
查看次数

Selenium Chrome Driver不尊重隐含的等待?

好的!所以我在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)

java selenium-webdriver

1
推荐指数
1
解决办法
5582
查看次数