PHP: cannot catch errors.
Posted: 2014-12-23T09:27:00-07:00
First, I'm French, i will try to speak English best as i can.
I'm running a server on Debian (Debian GNU/Linux 7) with php (5.4.35-0+deb7u2) and Apache.
I'm creating an API with Laravel, and i have a problem when i upload a file that Imagick can't use.
the exception occurs at:
When i upload a file that imagick can't use, Imagick throw an exception, but my code don't catch it and the server return code 500, But Laravel catch the error, i don't understand why. (I searched for many solutions on the web)
Can you help me guys?
thanks ♥
I'm running a server on Debian (Debian GNU/Linux 7) with php (5.4.35-0+deb7u2) and Apache.
I'm creating an API with Laravel, and i have a problem when i upload a file that Imagick can't use.
Code: Select all
static function createThumbWithHash($filePath, $fileHash) {
try
{
$im = new \imagick();
$im->setResourceLimit(\imagick::RESOURCETYPE_MEMORY, 1024);
$im->setResourceLimit(\imagick::RESOURCETYPE_MAP, 256);
$im->setResourceLimit(\imagick::RESOURCETYPE_AREA, 1512);
$im->setResourceLimit(\imagick::RESOURCETYPE_FILE, 768);
$im->setResourceLimit(\imagick::RESOURCETYPE_DISK, -1);
$tmpFile = tempnam(sys_get_temp_dir(), "thumb_");
$im->readImage($filePath);
$im->setImageFormat('jpg');
//Scale the image
$im->thumbnailImage(200, 200, true);
//Write the new image to a file
$im->writeImage($tmpFile);
} catch (ErrorDelegate $e) {
Log::info("getThumbHash: ".$e->getMessage());
return Response::json(array("error" => "Not image", "id" => "4", "desc" => "not image"), 418);
}
catch (Exception $e){
Log::info("getThumbHash: Unknown Error: " . $e->getMessage());
return Response::json(array("error" => "Unknown", "id" => "5", "desc" => "Unknown", "ErrorLevel" => "Error"), 418);
}
if (!self::moveFileToHash($tmpFile, $fileHash, "thumbnail"))
return false;
return true;
}
Code: Select all
$im->readImage($filePath);
Can you help me guys?
thanks ♥