Symfony 2重定向而不是未定义的偏移异常

My question for today is how to do in Symofny2 to redirect me to route instead show exception. For example i execute select in database and in return i get

Notice: Undefined offset: 0

So how can i redirect this exception to some route ? i use:

try{ 
   myMetdod()
}catch(ContextErrorException $e){
   $this->redirectToRoute('myRoute');
}

But it wont take any effect. Please help

You need to add return and call the method generateUrl()

try{ 
   myMetdod()
}catch(ContextErrorException $e){
   return $this->redirect($this->generateUrl('redirect-path'));
}