In my routing I would like to have something like not found route handler.
For example I have created one mapping like
routes.MapRoute( 'default', '{controller}/{action}/{id}', new { controller = 'Home', action = 'Index', id='' } ); routes.MapRoute( 'Catchall', '{*catchall}', new { controller = 'Home', action = 'Lost' } );
but when user inserts address something like /one/two/three/four/bla/bla it will be cached with the Catchall mapping.
But when user inserts something that should match with default mapping, (like /one/two/ ,but this controller or action is not implemented) I would want that Catchall mapping would accept this request, because all other mappings failed. But instead of this I get an error.
Should I override some mapping handlers to catch the exception if controller or action getting an exception?
The issue here is that it’s not the Route’s responsibility to make sure that ‘one/two’ maps to a file. That responsibility falls to the ViewEngine. Since ‘one/two’ is a valid route, it will be chosen.
If you want to handle the error of an invalid route, what I would recommend you do is simply use the built in ErrorHandling ‘page’ to display whatever message you would have done in the Catchall.