symfonyexceptionsilex

Not all exceptions caught within the error handler


Consider a Silex application with error handling:

$app->error(function (\Exception $exception, $code) use ($app, $locale) {
    die($exception->getMessage());    
});

For login purpose, an AuthenticationSuccessHandler is defined:

use Symfony\Component\Security\Core\Exception\AuthenticationException;
use Symfony\Component\Security\Http\Authentication\DefaultAuthenticationSuccessHandler;

class AuthenticationSuccessHandler extends DefaultAuthenticationSuccessHandler
{
    public function onAuthenticationSuccess(Request $request, TokenInterface $token)
    {
        ...
        
        if ($somethingWrong) {
            throw new AuthenticationException();
        }
        
        ...
    }
}

The AuthenticationException is not caught within the error handler.

Yet, throwing \RuntimeException or \Exception will be caught by the handler.

What am I missing here?


Solution

  • That's probably means that AuthenticationException has been catched and handled already beetween onAuthenticationSuccess and your closure, doesn't it?