1.2.1281. Unthrown Exception

These exceptions are defined in the code but never thrown. They are probably dead code.

Unused exceptions are code bloat, as they increase the size of the code without any purpose. They are also misleading, as other developers might come to the impression that there is a mechanism to handle the situation that the exception describe, yet they are generating a fatal error.

<?php

//This exception is defined but never used in the code.
class myUnusedException extends \Exception {}

//This exception is defined and used in the code.
class myUsedException extends \Exception {}

throw new myUsedException('I was called');

?>

1.2.1281.1. Suggestions

  • Remove the exception

  • Find a place in the code to throw the exception

  • Replace an existing Exception with this more specific one

1.2.1281.2. Specs

Short name

Exceptions/Unthrown

Rulesets

All, Analyze, Changed Behavior, Dead code

Exakat since

0.8.4

PHP Version

All

Severity

Minor

Time To Fix

Quick (30 mins)

Precision

Very high

Features

exception

ClearPHP

no-unthrown-exceptions

Available in

Entreprise Edition, Exakat Cloud