Comma is not a concatenation operator in PHP, Period is. Secondly, echo doesn't return the string back, it only outputs it. Remove the echo and save your string in your variable like this:
$error = 'Captured: '. $e->getMessage(). "\n";
Now you may wonder that if this is the case then why do you have an example on PHP.net having comma there?
echo 'Captured: ', $e->getMessage(), "\n";
It is because that is not string concatenation, those are 3 different parameters being sent to the echo command so in that case it is valid syntax, but for string concatenation it wont be.
echowhich doesn't need / want to be there.