Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [jgit-dev] JGit's overuse of IOException

Ah. Yes. I retract that API compatibility part. But I think still there's a value in defining a root exception.

I think you probably meant to quote p252 "Item 62: Document all exceptions thrown by each method". It says "Don't take the shortcut of declaring that a method throws some superclass of multiple exception classes that it can throw". I think the exception can inherit from this root exception for the caller's convenience, but still can specify the individual exceptions for each method. 

--
Masaya Suzuki
draftcode@xxxxxxxxx


On Tue, Nov 13, 2018 at 7:40 PM Jonathan Nieder <jrn@xxxxxxxxxx> wrote:
Hi,

Masaya Suzuki wrote:

By defining a root exception as Matthias mentioned it would become API safe when introducing a new exception.

I maintain that (outside of org.eclipse.jgit.api.*, which is imitating commandline tools) this is a bad idea.

Java is designed with the list of exceptions a caller needs to handle as part of an API. Fighting that has only brought us pain. It's better on a method by method basis to list the exceptions we want the caller to handle, at an appropriate level of abstraction. As the library evolves, we will sometimes discover we want to throw another exception, and at that point we should introduce a new method and deprecate the old one since it affects callers.

More details about this are in Effective Java second edition p251 "Item 61: Throw exceptions appropriate to the abstraction".

Thanks,
Jonathan
_______________________________________________
jgit-dev mailing list
jgit-dev@xxxxxxxxxxx
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://www.eclipse.org/mailman/listinfo/jgit-dev

Back to the top