Skip to main content

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

See https://bugs.eclipse.org/bugs/show_bug.cgi?id=366914

Cheers,
Tomasz

On Wed, May 16, 2012 at 7:39 PM, Mikael Karlsson <mmmicke@xxxxxxxxx> wrote:
> 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
> _______________________________________________
> jgit-dev mailing list
> jgit-dev@xxxxxxxxxxx
> https://dev.eclipse.org/mailman/listinfo/jgit-dev


Back to the top