1.2.1190. Throw Raw Exceptions

Avoid throwing native PHP exceptions. Consider defining specific and meaningful exception, by extending the native one.

Thanks to Atif Shahab Qureshi for the inspiration.

<?php

// Throwing a raw exception
throw new exception('This is an error!');

class myException extends Exception {}

throw new myException('This is a distinguished error!');

?>

See also Stop using regular exceptions in PHP!.

1.2.1190.1. Suggestions

  • Define an adapted exception and throw it instead

1.2.1190.2. Specs

Short name

Exceptions/ThrowRawExceptions

Rulesets

All, Analyze, Suggestions

Exakat since

2.4.0

PHP Version

All

Severity

Minor

Time To Fix

Quick (30 mins)

Precision

Very high

Features

exception

Available in

Entreprise Edition, Exakat Cloud