17

When I use this code in Laravel framework:

throw new Exception("failed");

it throws this error:

FatalErrorException in MyController.php line 178: Class 'App\Http\Controllers\Exception' not found

Does anybody know how can I use (include) that Exception class to my controller? Where is actually it?

1
  • 3
    It's \Exception, your code is namespaced Commented Jan 1, 2017 at 11:26

1 Answer 1

46

Throw the exception using the following code.

throw new \Exception("failed");

Otherwise, import the class before using.

use Exception;
Sign up to request clarification or add additional context in comments.

1 Comment

how the pro developers handle throws in laravel?

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.