当试图捕获/处理从PDFParser抛出的异常时,我无法捕捉它。我使用了一个简单的try catch语句,如下所述。PHP异常未被捕获,laravel,流明
try{
$pdf = $parser->parseFile($filepath);
$text = $pdf->getText();
} catch(\Exception $e){
$text = $paper->abstract;
}
引发异常如下。
if (empty($data)) {
throw new \Exception('Object list not found. Possible secured file.');
}
The output is here.
lumen.ERROR: Exception: Object list not found. Possible secured file. in
/Users/pietrosette/Documents/CS_310/AcademicWordCloud-Backend/vendor/smalot/pdfparser/src/Smalot/PdfParser/Parser.php:98 Stack trace:
#0 /Users/pietrosette/Documents/CS_310/AcademicWordCloud-Backend/vendor/smalot/pdfparser/src/Smalot/PdfParser/Parser.php(74): Smalot\PdfParser\Parser->parseContent('%PDF-1.5\r%\xE2\xE3\xCF\xD3\r...')
#1 /Users/pietrosette/Documents/CS_310/AcademicWordCloud-Backend/app/Http/Controllers/ACMServer.php(198): Smalot\PdfParser\Parser->parseFile('/Users/pietrose...')
感谢您的编辑,但它仍然无法正常工作。 –
这仍然是一个错误吗? – suecarmol
是的,我最终将其更改为: if($ pdf ===“PDF> = 1.5”){ $ text =“paper-> abstract”;其他{ } $ text = $ pdf-> getText(); } 与 公共函数parseFile($文件名) { $含量=的file_get_contents($文件名)的一个包装; $ return = @ $ this-> parseContent($ content); if($ return === false){ return“PDF> = 1.5”; } else { return $ return; } } –