Catching a NotFoundHttpException in the web.php file of Laravel 5.4 and throwing a custom exception -


i'm trying find way of customising error handling of laravel 5.4 when route can't found. in web.php there route incorrectly defined (deliberately testing purposes). have wrapped in try...catch block , thrown own custom exception routesexception:

try {     route::get('terms_rop_labels/view', 'lrchildcontroller@view'); }catch (notfoundhttpexception $ex) {     throw new routesexception('terms_rop_labels/view'); } 

then in app\exceptions\handler.php trying catch exception in test view:

if ($exception instanceof notfoundhttpexception) { $parameters = [ 'message'=> 'notfoundhttpexception' ]; return response()->view('errors.test', $parameters, 500); } if ($exception instanceof routesexception) {         $parameters = [             'message'=> 'routesexception'         ];         return response()->view('errors.test', $parameters, 500); } 

can explain why handler catches notfoundhttpexception , not custom routesexception?

the route in web.php not throwing notfoundhttpexception exception. registering routes in web.php, not resolving them.

the route facade in web.php giving static access method in illuminate\routing\router class (see lines of 125 - 135 in https://github.com/laravel/framework/blob/5.4/src/illuminate/routing/router.php)

/**  * register new route router.  *  * @param  string  $uri  * @param  \closure|array|string|null  $action  * @return \illuminate\routing\route  */ public function get($uri, $action = null) {     return $this->addroute(['get', 'head'], $uri, $action); } 

(so adding routes routecollection router method in web.php file.)

if in back-trace, can see notfoundhttpexception exception being thrown in case. example, if navigate nonexistent route have not added route collection registering in web.php, see notfoundhttpexception being thrown routecollection class match method on line 179.

in case, try/catch in not catching notfoundhttpexception because the

route::get('terms_rop_labels/view', 'lrchildcontroller@view'); 

is not throwing notfoundhttpexception.

maybe can achieve want catching notfoundhttpexception in app\exceptions\handler instead.


Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -