Reputation: 1739
Look at this simple code:
public function test(){
if(sth){ //true
throw new Exception("Bla Bla");
}
}
And function in controller:
try {
test();
} catch (Exception $e) {
$toSend = $e->getMessage();
return $this->render('view.html.twig', array('toSend' => $toSend);
}
I want that function in controller render view.twig.html
and send 'Bla Bla' in toSend
variable.
While I'm getting 500 Internal Server Error - Exception
Best Regards
Upvotes: 0
Views: 261
Reputation: 528
I see there is some syntax error in your code.
throw new \Exception("Bla Bla")
instead of throw Exception("Bla Bla")
catch (\Exception $e)
instead of catch (Exception $e)
If you dont put "\" before Exception class, it means that it will find Exception class in your current namespace. If it can't find it, it will throw exception.
Upvotes: 4