Troubleshooting of Sonar issue: Difference between revisions
Jump to navigation
Jump to search
m (→References) |
|||
| Line 6: | Line 6: | ||
Error condition which met "Define and throw a dedicated exception instead of using a generic one" <ref>[https://cwe.mitre.org/data/definitions/397 CWE - CWE-397: Declaration of Throws for Generic Exception (4.12)]</ref> | Error condition which met "Define and throw a dedicated exception instead of using a generic one" <ref>[https://cwe.mitre.org/data/definitions/397 CWE - CWE-397: Declaration of Throws for Generic Exception (4.12)]</ref> | ||
<pre> | <pre> | ||
if( | if(is_null($some_variable)){ | ||
$error = 'The variable $some_variable is not defined.'; | $error = 'The variable $some_variable is not defined.'; | ||
throw new Exception($error); | throw new Exception($error); | ||
Revision as of 16:48, 7 September 2023
How to resolve "Define and throw a dedicated exception instead of using a generic one"
Error condition which met "Define and throw a dedicated exception instead of using a generic one" [1]
if(is_null($some_variable)){
$error = 'The variable $some_variable is not defined.';
throw new Exception($error);
}
Possible solution
if(!is_null($some_variable)){
$error = 'The variable $some_variable is not defined.';
throw new InvalidArgumentException($error);
}
Further reading
References
Troubleshooting of ...
- PHP, cUrl, Python, selenium, HTTP status code errors
- Database: SQL syntax debug, MySQL errors, MySQLTuner errors or PostgreSQL errors
- HTML/Javascript: Troubleshooting of javascript, XPath
- Software: Mediawiki, Docker, FTP problems, online conference software
- Test connectivity for the web service, Web Ping, Network problem, Web user behavior, Web scrape troubleshooting
Template