Error handling with try and catch in Laravel

后端 未结 1 1696
梦如初夏
梦如初夏 2021-02-11 14:29

I want to implement a good error handling in my app, I have forced this file for catching the error.

App\\Services\\PayUService

try {
           


        
1条回答
  •  深忆病人
    2021-02-11 15:16

    You are inside a namespace so you should use \Exception to specify the global namespace:

    try {
    
      $this->buildXMLHeader();
    
    } catch (\Exception $e) {
    
        return $e->getMessage();
    }
    

    In your code you've used catch (Exception $e) so Exception is being searched in/as:

    App\Services\PayUService\Exception
    

    Since there is no Exception class inside App\Services\PayUService so it's not being triggered. Alternatively, you can use a use statement at the top of your class like use Exception; and then you can use catch (Exception $e).

    0 讨论(0)
提交回复
热议问题