Hi everyone,
Bruce Eckel brought up the issue that most APIs lack a description of possible exceptions¹.
While looking into it, I realized that the current way to do it is very boilerplatey:
/** This method does ... * @throws IllegalArgumentException if `a` is less than 0. */@throws(classOf[IllegalArgumentException])def foo(a: Int) = ...Without great IDE ScalaDoc support (which is not there), this stuff can very easily become out of sync or outdated.
As the guy implementing the @throws ScalaDoc tag in the first place, I guess it is my task to clean that up...
in the best tradition of "let's add a second parameter to @migration/@deprecated/...", I propose something like this instead:
@throws(classOf[IllegalArgumentException], "if `a` is less than 0.")def foo(a: Int) = ...Normally, I would be reluctant to add some documentation-specific value to an annotation, but I think we could gain some additional benefit from it in later versions.
Imagine some compiler-mode (or macro )which will warn if a method will very likely throw an error for the given arguments!
Normally, this would be a Turing-complete task, but an useful subset could be verified by embedding code snippets into the @throws annotation like this:
@throws(classOf[IllegalArgumentException], "`if (a < 0)`")
def foo(a: Int) = ...This way we would benefit from less boilerplatey documentation and be able to use the information during compilation if we want to do that in future versions!
This is of course purely hypothetical, but after sleeping a night over it, I think I'm in favor of adding a second parameter to the @throws annotation and deprecating the ScalaDoc @throws tag.
What do you think?
Thanks and bye,
Simon
¹
https://groups.google.com/forum/?hl=en_US#!topic/scala-user/3vfNJdGtyxw