DEV Community

Krixnaas
Krixnaas

Posted on

Better way of using TryCatch in PHP | Laravel

Provide you a timestamp, message as well as path

 try{

  // your code 

 } catch (Exception $exception) {
            return Response::json([
                "timestamp" => date('Y-m-d\TH:i:s.vP'),
                "status" => 400,
                "error" => "Bad Request",
                "message" => $exception->getMessage(),
                "path" => \Request::getRequestUri()
            ], 400);
        }
Enter fullscreen mode Exit fullscreen mode

Top comments (0)