I sometime use throw inside a try catch when I feel like it makes sense, for example to do extra verifications on user input (see example below).
Expected behavior
Do nothing
Observed behavior
KDOC_WITHOUT_THROWS_TAG rule add a @throws annotation to the function, but it's wrong, this function does not throw anything as it is already caught by the surrounding try catch
Steps to Reproduce
/**
* @throws NumberFormatException
*/
fun parseInputNumber(onSuccess: (number: Int) -> Unit, onFailure: () -> Unit) {
try {
val input: Int = binding.inputEditText.text.toString().toInt()
if (input < 0)
throw NumberFormatException()
onSuccess(input)
} catch (e: NumberFormatException) {
onFailure()
}
}
Hey! thank you for this report! Sounds reasonable, looks like we implemented it in a very-very simple way.
Need to think of how to do it properly. Until fixed you can use @Suppress annotation
Describe the bug
I sometime use
throw
inside atry catch
when I feel like it makes sense, for example to do extra verifications on user input (see example below).Expected behavior
Do nothing
Observed behavior
KDOC_WITHOUT_THROWS_TAG
rule add a@throws
annotation to the function, but it's wrong, this function does not throw anything as it is already caught by the surrounding try catchSteps to Reproduce
Environment information