try
{
$picture = PDF_open_image_file($PDF, "jpeg", $imgFile, "", 0); // This is the original statement, this works on PHP4
}
catch(Exception $ex)
{
$msg = "Error opening $imgFile for Product $row['Identifier']";
throw new Exception($msg);
}
Inside complex code parts (for exemple multiple loops, complex data constructions…), avoid using try…catch.
When an exception is thrown, a variable (the exception itself) is created in a catch block and it’s destruction consumes unnecessary CPU cycles and RAM. Prefer using logical tests in this cases.
try
{
$picture = PDF_open_image_file($PDF, "jpeg", $imgFile, "", 0); // This is the original statement, this works on PHP4
}
catch(Exception $ex)
{
$msg = "Error opening $imgFile for Product $row['Identifier']";
throw new Exception($msg);
}
//try
if (file_exists($imgFile)) {
$picture = PDF_open_image_file($PDF, "jpeg", $imgFile, "", 0);
}
//catch
if (!$picture) {
$msg = "Error opening $imgFile for Product $row['Identifier']";
print $msg;
}
Energy: measured in joules (J)
Transfer: measured in Bytes (B)
Storage: measured in Bytes (B)
The control of these 3 impacts allows to lengthen the life of the terminals as well as reduce their energy consumption.
The ETSdiff tool allows measuring a differential on these three values and in a given context (database and fixed measurement environment).
The results generated by ETSdiff must help define the interest of the rule reported by SonarQube in the context of the code analyzed.
| Source of impacts | Compliant | Non-compliant |
|---|---|---|
Energy (J) |
515.855638 |
516.9188409999999 |
Transfer (B) |
1579453 |
1579457 |
Storage (B) |
637549804 |
637549804 |