Skip to content

Commit c3bb701

Browse files
committed
Merge pull request #932 from jalliot/exception
Use more precise exception type in new cookbook
2 parents 5034f36 + 19e946f commit c3bb701

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

cookbook/security/entity_provider.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,7 @@ The code below shows the implementation of the
327327
use Symfony\Component\Security\Core\Exception\UsernameNotFoundException;
328328
use Symfony\Component\Security\Core\Exception\UnsupportedUserException;
329329
use Doctrine\ORM\EntityRepository;
330+
use Doctrine\ORM\NoResultException;
330331

331332
class UserRepository extends EntityRepository implements UserProviderInterface
332333
{
@@ -344,7 +345,7 @@ The code below shows the implementation of the
344345
// The Query::getSingleResult() method throws an exception
345346
// if there is no record matching the criteria.
346347
$user = $q->getSingleResult();
347-
} catch (\Exception $e) {
348+
} catch (NoResultException $e) {
348349
throw new UsernameNotFoundException(sprintf('Unable to find an active admin AcmeUserBundle:User object identified by "%s".', $username), null, 0, $e);
349350
}
350351

0 commit comments

Comments
 (0)