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?
All exceptions are handled by the App\Exceptions\Handler class. This class contains a register method where you may register custom exception reporting and rendering callbacks.
To do that, you can specify Route::fallback() method at the end of routes/api. php, handling all the routes that weren't matched. Route::fallback(function(){ return response()->json([ 'message' => 'Page Not Found. If error persists, contact [email protected]'], 404); });
Throw the exception using the following code.
throw new \Exception("failed");
Otherwise, import the class before using.
use Exception;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With