Skip to content

Files

Latest commit

 

History

History
46 lines (32 loc) · 1.25 KB

Squiz.Commenting.EmptyCatchComment.md

File metadata and controls

46 lines (32 loc) · 1.25 KB

Pattern: Empty catch comment

Issue: -

Description

Checks for empty catch clause without a comment. It's rarely correct to do nothing in response to a caught exception. Typical responses are to handle it, log it, or if it is considered "impossible", rethrow it.

When it truly is appropriate to take no action whatsoever in a catch block, this rule enforces to have a comment to explain the reason this is justified.

Example

Example of incorrect code:

public function saveFile($filename)
{
	$file = PhpFile::instance($filename);
	
	try {
		$file->lock();
	} catch (Exception $ex) {
	
	}
}

Example of correct code:

public function saveFile($filename)
{
	$file = PhpFile::instance($filename);
	
	try {
		$file->lock();
	} catch (Exception $ex) {
		// Another process has locked the file; we will handle this in a bit.
	}
}

Further Reading