Answers for "catch all exception laravel"

PHP
7

try and catch laravel

try {

  $this->buildXMLHeader();

} catch (\Exception $e) {

    return $e->getMessage();
}
Posted by: Guest on April-22-2021
1

how to catch query exception in laravel 8

try { 
  $results = \DB::connection("example")
    ->select(\DB::raw("SELECT * FROM unknown_table"))
    ->first(); 
    // Closures include ->first(), ->get(), ->pluck(), etc.
} catch(\Illuminate\Database\QueryException $ex){ 
  dd($ex->getMessage()); 
  // Note any method of class PDOException can be called on $ex.
}
Posted by: Guest on December-02-2020

Browse Popular Code Answers by Language