3

I'm using SVNKit and the only way I found out to test Authentification to the server is by using method testConnection() of class SVNRepository.

The method doesn't return a boolean but throws an Exception.

public abstract void testConnection()
                         throws SVNException

The problem is that, instead of being catch, I get a coldfusion error : coldfusion error in try catch (SVNRepository.testConnection())

Here is my code:

        clientManager = CreateObject("java", "org.tmatesoft.svn.core.wc.SVNClientManager").newInstance();

        authManagerJO = CreateObject("java", "org.tmatesoft.svn.core.wc.SVNWCUtil").
                createDefaultAuthenticationManager(ARGUMENTS.username, JavaCast("String", ARGUMENTS.password));
        authManagerJO.setAuthenticationForced(true);
        clientManager.setAuthenticationManager(authManagerJO); 
        svnDavRepoFactory = CreateObject("java", "org.tmatesoft.svn.core.internal.io.dav.DAVRepositoryFactory").setup();
        repositoryUrlJO = CreateObject("java", "org.tmatesoft.svn.core.SVNURL").parseURIDecoded(APPLICATION.svn_repository_audifiles);
        svnRepository = clientManager.createRepository(repositoryUrlJO, true);
        try{
            svnRepository.testConnection();
        }
        catch (Exception e){
            svnRepository = "";
        }
Francis P
  • 13,377
  • 3
  • 27
  • 51

3 Answers3

7

Well, it's entirely possible that it's throwing an exception which isn't an Exception - another kind of Throwable. You could catch Throwable, although that would be pretty harsh... catching it once, logging the exact exception type and then catching that would be reasonable though...

Jon Skeet
  • 1,421,763
  • 867
  • 9,128
  • 9,194
  • Alternately, you could check the API and find out exactly what kind of Throwable it throws, and catch that (or those). – jpm Mar 30 '12 at 19:49
  • @jpm: Assuming it's documented, of course - which it may not be, if it's an unchecked exception... – Jon Skeet Mar 30 '12 at 19:50
  • I would assume a method for testing a connection (and doesn't return a boolean) would have the only thing making it useful documented. Then again, I am a bit of an optimist. – jpm Mar 30 '12 at 19:53
  • @jpm: I'd have hoped they'd use *either* a checked exception *or* a subclass of RuntimeException, but apparently that's not the case... – Jon Skeet Mar 30 '12 at 19:54
  • according to the documentation, it does throw an `SVNException` which `extends Exception`. (http://svnkit.com/javadoc/org/tmatesoft/svn/core/io/SVNRepository.html#testConnection%28%29) – Francis P Mar 30 '12 at 20:01
  • @FrancisP - I know you fixed it using `any`, but out of curiosity did you try specifying the full path in the catch clause instead of just `Exception` or `SVNException`? – Leigh Mar 30 '12 at 20:43
  • @Leigh: What do you mean by *full path* ? – Francis P Mar 30 '12 at 20:46
  • 1
    @FrancisP - The full path to the exception class, like `org.tmatesoft.svn.core.SVNException` or `java.lang.Exception` – Leigh Mar 30 '12 at 21:13
2

Did you try catching Any instead of Exception ?

This way, you will be sure to catch everything, even if the exception is not an Exception like Jon proposed.

Pierre-Olivier
  • 3,104
  • 19
  • 37
0

Do

catch (any e) {
    write dump(e);
    abort;
}

Then you'll see the actual error.

baynezy
  • 6,493
  • 10
  • 48
  • 73