0

I'm looking for any way to handle the QueryException using the laravel framework.

Is there any possible way to prevent the usual user from getting such an error with a handler?

I tried to prevent that black detailed error page not to be visible to any user.

6
  • Does this answer your question? How do I catch a query exception in laravel to see if it fails? Commented Jan 18, 2021 at 18:13
  • @ s.wadhwa yes it does work. But I'm looking for something to be applied to all functions. Commented Jan 18, 2021 at 18:17
  • 1
    Set APP_DEBUG to false in the .env file Commented Jan 18, 2021 at 18:28
  • You can also look the Ashraf Hefny answer in the question provided by s.wadhwa to apply it to all functions. Commented Jan 18, 2021 at 18:34
  • 1
    There's a whole section in the documentation on error handling. I suggest you take a look at that as well, but most important is setting APP_DEBUG to false for non development environments. Commented Jan 18, 2021 at 19:04

1 Answer 1

1

Catch an exception on using try-catch statements :

Use Exception;

try
{
   // write your codes here
}
catch(\Exception $e)
{
   //dd($e->getMessage());
   return "Something Went Wrong";
}

If you want to catch PDO Exception :

use PDOException;

try
{
   //write your codes here
} 
catch(\PDOException $e)
{
   //dd($e->getMessage());
   return "Something Went Wrong":
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.