Check for errors when getting a cursor to avoid "maybe uninitialized" warning.