New error handling and associated tests

Per PR discussion.