Replace undefined variable $error by message got from exception object