我正在为SVNKit的异常而苦苦挣扎。 我强制验证失败以测试我的应用程序,并为此编写了这段代码:
...
import org.tmatesoft.svn.core.SVNAuthenticationException;
...
private def connectRepository(url : String, user : String, pass : String) : SVNRepository = {
val repository = SVNRepositoryFactory.create(SVNURL.parseURIDecoded(url))
try {
val authManager = SVNWCUtil.createDefaultAuthenticationManager(user,pass)
repository.setAuthenticationManager(authManager)
} catch {
case e: SVNAuthenticationException => {println("Gotcha!"); System.exit(-1)}
}
repository
}
但是,我无法捕捉到异常。在我的控制台中,我收到此消息,而不是“ Gotcha!”:
Exception in thread "main" org.tmatesoft.svn.core.SVNAuthenticationException: svn: E170001: Authentication required for 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
at org.tmatesoft.svn.core.internal.wc.SVNErrorManager.authenticationFailed(SVNErrorManager.java:53)
at org.tmatesoft.svn.core.internal.wc.SVNErrorManager.authenticationFailed(SVNErrorManager.java:47)
at org.tmatesoft.svn.core.internal.wc.DefaultSVNAuthenticationManager.getNextAuthentication(DefaultSVNAuthenticationManager.java:233)
at org.tmatesoft.svn.core.internal.io.dav.http.HTTPConnection.request(HTTPConnection.java:690)
at org.tmatesoft.svn.core.internal.io.dav.http.HTTPConnection.request(HTTPConnection.java:352)
at org.tmatesoft.svn.core.internal.io.dav.http.HTTPConnection.request(HTTPConnection.java:340)
at org.tmatesoft.svn.core.internal.io.dav.DAVConnection.performHttpRequest(DAVConnection.java:910)
at org.tmatesoft.svn.core.internal.io.dav.DAVConnection.exchangeCapabilities(DAVConnection.java:702)
at org.tmatesoft.svn.core.internal.io.dav.DAVConnection.open(DAVConnection.java:113)
at org.tmatesoft.svn.core.internal.io.dav.DAVRepository.openConnection(DAVRepository.java:1047)
at org.tmatesoft.svn.core.internal.io.dav.DAVRepository.checkPath(DAVRepository.java:208)