Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/249.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/laravel/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP异常未被捕获,laravel,lumen_Php_Laravel_Exception_Exception Handling_Lumen - Fatal编程技术网

PHP异常未被捕获,laravel,lumen

PHP异常未被捕获,laravel,lumen,php,laravel,exception,exception-handling,lumen,Php,Laravel,Exception,Exception Handling,Lumen,当试图捕获/处理从引发的异常时,我无法捕获它。我使用一个简单的try-catch语句,如下所述 try{ $pdf = $parser->parseFile($filepath); $text = $pdf->getText(); } catch( \Exception $e){ $text = $paper->abstract; } 异常抛出如下 if (empty($data)) { throw new \Exception('Obj

当试图捕获/处理从引发的异常时,我无法捕获它。我使用一个简单的try-catch语句,如下所述

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.');
}
输出在这里

lumen.ERROR:异常:找不到对象列表。可能的安全文件。 在

/Users/pietrosette/Documents/CS_310/academicrordcloud Backend/vendor/smalot/pdfparser/src/smalot/pdfparser/Parser.php:98 堆栈跟踪:

#0/Users/pietrosette/Documents/CS_310/academicrordcloud 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/academicrordcloud Backend/app/Http/Controllers/ACMServer.php(198): Smalot\PdfParser\Parser->parseFile(“/Users/pietrose…”)


您的捕获有一个输入错误:

try{
  $pdf  = $parser->parseFile($filepath);
  $text = $pdf->getText();    
} catch( \Execption $e){
  $text = $paper->abstract;
}

“例外”拼写错误。

您的捕获中有一个输入错误:

try{
  $pdf  = $parser->parseFile($filepath);
  $text = $pdf->getText();    
} catch( \Execption $e){
  $text = $paper->abstract;
}

“Exception”拼写错误。

我最后编写了一个包装并返回了一个不同的值。这最终起到了作用,实际上速度要快得多,因为它没有封装在try/catch块中

    public function parseFile($filename)
    {
        $content = file_get_contents($filename);
        $return = @$this->parseContent($content);
        if($return === false ){
            return "PDF >= 1.5";
        } else{
            return $return;
        }
    }


    public function parseContent($content)
    {
        ...

        if (isset($xref['trailer']['encrypt'])) {
            return false;
        }

        if (empty($data)) {
            return false;
        }
        ....
   }
这导致将我的函数修改为以下内容

    $pdf = $parser->parseFile($filepath);

    if($pdf === "PDF >= 1.5" ){
        $text = $abstract;
    } else  {
        $text = $pdf->getText();
    }

我最终编写了一个包装器并返回了一个不同的值。这最终起到了作用,实际上速度要快得多,因为它没有封装在try/catch块中

    public function parseFile($filename)
    {
        $content = file_get_contents($filename);
        $return = @$this->parseContent($content);
        if($return === false ){
            return "PDF >= 1.5";
        } else{
            return $return;
        }
    }


    public function parseContent($content)
    {
        ...

        if (isset($xref['trailer']['encrypt'])) {
            return false;
        }

        if (empty($data)) {
            return false;
        }
        ....
   }
这导致将我的函数修改为以下内容

    $pdf = $parser->parseFile($filepath);

    if($pdf === "PDF >= 1.5" ){
        $text = $abstract;
    } else  {
        $text = $pdf->getText();
    }

还是同样的错误吗?是的,我最后把它改为:if($pdf==“pdf>=1.5”){$text=“paper->abstract”}或者{$text=$pdf->getText();}带有公共函数parseFile($filename){$content=file\u get\u contents($filename)的包装;$return=@$this->parseContent($content);if($return===false){return“PDF>=1.5”}else{return$return;}还是同样的错误吗?是的,我最后把它改为:if($PDF==“PDF>=1.5”){$text=“paper->abstract”}else{$text=$pdf->getText();}带有公共函数parseFile($filename){$content=file_get_contents($filename);$return=@$this->parseContent($content);if($return==false){return“pdf>=1.5”;}else{return return$return;}