Exception description specifications in PHP function documentation: Format: @throws |Exception Name| Exception descriptionException Name: The fully qualified name of the exception classException description: Use complete sentences to describe the cause of the exception and avoid vague wording
PHP function document exception description specifications
In PHP function documentation, the description of exceptions should follow the following specifications:
Description format :
@throws |Exception Name| Exception description
Exception Name:
Throwable
as a base class. Exception description:
Practical case:
The following example demonstrates the correct format of the exception description:
/** * 打开一个文件。 * * @param string $filename 文件名 * @param string $mode 打开模式 * @return resource 打开的文件指针 * * @throws \Exception 文件无法打开时抛出。 */ function fopen(string $filename, string $mode): resource { // ... throw new \Exception("无法打开文件:$filename"); }
Note:
The above is the detailed content of What are the requirements for describing function exceptions in the PHP function documentation specification?. For more information, please follow other related articles on the PHP Chinese website!