當試圖捕獲/處理從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; } } –