Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[jgit-dev] Exceptions in JGit

Hi,

I am curious about the Exception policy in JGit. Many methods throw _a
lot_ of Exceptions. For a third-party application using JGit, there
are many different exceptions to catch, and the code can quickly get
kind of ugly (IMHO).

For example, why do we do this:
public RevCommit call() throws NoHeadException, NoMessageException,
			UnmergedPathException, ConcurrentRefUpdateException,
			JGitInternalException, WrongRepositoryStateException {

when we could do this:
public RevCommit call() throws GitAPIException {


And why do we do this:
try {
	...
} catch (NoHeadException e) {
	throw new JGitInternalException(e.getMessage(), e);
} catch (ConcurrentRefUpdateException e) {
	throw new JGitInternalException(e.getMessage(), e);
} catch (CheckoutConflictException e) {
	throw new JGitInternalException(e.getMessage(), e);
} catch (InvalidMergeHeadsException e) {
	throw new JGitInternalException(e.getMessage(), e);
} catch (WrongRepositoryStateException e) {
	throw new JGitInternalException(e.getMessage(), e);
} catch (NoMessageException e) {
	throw new JGitInternalException(e.getMessage(), e);
}

when we could do this:
try {
	...
} catch (GitApiException e) {
	throw new JGitInternalException(e.getMessage(), e);
}


I am currently trying to add a feature that involves adding a new
Exception class. I had to change method signatures all over the place,
which is of course not good at all if we want to have a stable public
API. If methods woud just throw GitApiException instead of all the
others, we wouldn't have to change the method signatures when we add a
new Exception.

Do you agree - or am I missing the point?

Regards,
Mikael Karlsson


Back to the top