When should exceptions be documented?

Assume the following snippet:

public function foo() 
{
    return $this->dependency->bar();
}

If dependency::bar(), as you know, throws an exception, but foo()will not handle it. Should foo()have an entry @throwsin docblock? Or should it be implicit? The phpdoc documentation is somewhat vague.

Assuming what dependencyis introduced based on the interface; whether an interface document must be in order for the method to raise the specified exception.

Does it matter whether the exception should be handled by the calling code or is this not relevant?

Semantics completely :)

+4
source share
1 answer

( ), - , @throws docblock.
- - , -, , , .

- , , , .

try-catch , @throws .

+2

Source: https://habr.com/ru/post/1687224/


All Articles