تخطَّ إلى المحتوى

Swallowed Exception (ARCH7151)

هذا المحتوى غير متوفر بلغتك بعد.

Key php.logging.swallowed-exception · Severity warning · Category logging

Catching an exception and silently returning null/false hides the failure. Unlike an empty block, the body exists but the exception is still discarded.

<?php
public function loadConfig(string $path): ?array
{
try {
return json_decode(file_get_contents($path), true);
} catch (\Throwable $e) {
return null;
}
}
<?php
public function loadConfig(string $path): ?array
{
try {
return json_decode(file_get_contents($path), true);
} catch (\Throwable $e) {
$this->logger->error('Config load failed', ['path' => $path, 'exception' => $e]);
throw $e;
}
}

Log or rethrow the exception instead of silently converting it to a return value.