1.2.1200. 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.1200.1. Connex PHP features¶
1.2.1200.1.1. Suggestions¶
Define an adapted exception and throw it instead
1.2.1200.1.2. Specs¶
Short name |
Exceptions/ThrowRawExceptions |
Rulesets |
|
Exakat since |
2.4.0 |
PHP Version |
All |
Severity |
Minor |
Time To Fix |
Quick (30 mins) |
Precision |
Very high |
Available in |