Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialbruce zhang
1,317 Pointshow to Try Cache exceptions for orm query?
Hi, I try to catch exception for example if I put id = 5 (not in my database) then laravel redirect me to the error page, I tried use try catch, but it still redirect me there
try{
$list = \TodoList::find($id);
}catch(\Exception $e) {
dd("something not right");
};
return View::make('todos.show')
->withList($list);
would you help please? thanks
1 Answer
Petros Sordinas
16,181 PointsBruce,
What is the error you are getting?
With find(), you have to check if the result is null. It won't return an error if the id is not found. You may want to use findOrFail() which throws a ModelNotFound exception with the id is not found.