1

I have tried to define custom exception class in Laravel 5.3.But i couldn't find any solution.

How can i define and call custom exception class inside API controller in Laravel 5.3.Any help would be much appreciated..

1 Answer 1

3

Write a new CustomException class and extends the \Exception class:

CustomException extends \Exception {}

to use your custom exception class this is an example of use in controller:

public function someAction() {
  throw new CustomException('your message error')
   // or
  try {
  } catch (Exception $e) {
     throw new CustomException($e->getMessage());
     // ...
  }
}
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.