how to catch query exception in laravel 8

Solutions on MaxInterview for how to catch query exception in laravel 8 by the best coders in the world

we are a community of more than 2 million smartest coders
registration for
employee referral programs
are now open
get referred to google, amazon, flipkart and more
register now
  
pinned-register now
showing results for - "how to catch query exception in laravel 8"
Mirko
23 Jul 2020
1try { 
2  $results = \DB::connection("example")
3    ->select(\DB::raw("SELECT * FROM unknown_table"))
4    ->first(); 
5    // Closures include ->first(), ->get(), ->pluck(), etc.
6} catch(\Illuminate\Database\QueryException $ex){ 
7  dd($ex->getMessage()); 
8  // Note any method of class PDOException can be called on $ex.
9}
10