You have to use Kernel Events. you can see an exemple here: Symfony2 logging 404 errors
and test the exception with $exception->getStatusCode()
public function onKernelException(Event $event) {
//Get hold of the exception
$exception = $event->getException();
if ($exception->getStatusCode() == 404)
{
//Do stuffs
}
}